0
Adding a model as a subdocument in another model which is in a separate file
I am using having serious issues with performing this task. Can someone put me through on how it is done. I use mongoose and node.js
2 ответов
0
In the model you want to add to, whatever field your adding to should be an array of objectsId's that reference the the other model you want added.
For example, add a new friend:
USER MODEL
......
friend: [{ type: mongoose.Schema.Types.ObjectId, ref: 'User'}],
.....
Then in your /add-friend route, you update the model by pushing the friends ID to the friend array.
https://stackoverflow.com/questions/18001478/referencing-another-schema-in-mongoose#18002078
0
Thanks you very much Jonny Legend