K
K
krumza2016-07-18 12:07:28
MongoDB
krumza, 2016-07-18 12:07:28

Is field dependency possible in mongodb?

There is a user model with a block of his experience (xp)

...
 stats    : {
...
        xp:             { type: Number, default: 0 }
    },
...

There is a dependence of the user level on his xp. When recruiting a certain amount of xp, the user increases his level.
At the moment, I can only see the output of the level - through a template (through conditions) or through front-end scripts (which is essentially the same).
The question is how to implement user-level storage and trigger events to change the user level?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
lega, 2016-07-18
@lega

On the server where the function changes xp, let the level be calculated and written to the base with the same update, for the event - immediately check if the level has changed and do something, for example, send a message to the client.

N
napa3um, 2016-07-18
@napa3um

Schemes describing the dependencies of fields, validators and limiters are built on top of the NoSQL storage, usually. In the case of MongoDB, this add-on could be Mongoose, which supports calculated fields: mongoosejs.com/docs/guide.html#virtuals .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question