node.js - Why Mongoose saves references of child ids in parent model? -


I am trying to log into MongoDB and Node.js and found that the most recommended module for using is Mongoose I liked the idea of ​​making a schema like my SQL and it is very easy to use.

One thing I did not understand is about references. date, default: date.nuh}, customer: {Type: string, required: true}, event: [{type: schema type. Object, ref: 'event', required: true}]}); Var EventSchema = New schema ({Created: {Type: Date, Default: Date.nuh}, Session: {Type: schema. Object ID, Ref: 'Session', ChildPath: 'Events', Required: True} , Data: schema type. Mixed});

Now the question is - why do I need to reference Event ID from within the session? Why not just ask events.Model.Fund ({session: session._id})?

I am afraid that this will create large session documents because there can be hundreds of events in one session.

What am I missing here?

Depends well, generally the common path is to create those types of references To populate your query with the data referenced in the form, as I have removed from the population documentation:

No one is involved in mangodibi, but sometimes we are in other collections The context of the documents also wants to be the place where the population comes.

If you are interested in the population then you take a peak

You can not harm it manually, depending on your needs and Your Questions


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -