Extending User schema


#1

I use mongoDb as persistence adapter. I already have existing User table in the database which uses different schema than the one jovo use. Is there a way to extend jovo User schema with fields that I have in existing Users table so that they get picked up when User is loaded?


#2

It’s not intended but we can give it a try :slight_smile:

How does your existing schema look like?

Disclaimer: I’m not a MongoDb expert at all :smiley:


#3

Just as an example, I have ‘answeredQuestions’ array at the root of an existing user. Do you know a way, before loading user, how to inject this field to an existing jovo user schema? Data is loaded on user.load event, so I probably would need to change schema before that.


#4

Sorry, didn’t have the time to dive deeper into it yet.


#5

So you mean instead of something like this:

{
   userId: 'id',
   userData: {
       data: {
             answeredQuesttions: ['a', 'b', 'c']
        }
  }

you have

{
   userId: 'id',
 answeredQuesttions: ['a', 'b', 'c']
}

?


#6

Yes, there are other fields too of course, but this is one of them.


#7

Hm, I looked into the code and I can’t find a workaround. I would recommend building a migrating script.
Something that maps answeredQuestions to userData.data.answeredQuestions.


#8

In that case I’ll figure something out. Thank you for looking into it.