Skip to content

Uncertainty about usage of populate() #10497

Answered by vkarpov15
f0o asked this question in Q&A
Discussion options

You must be logged in to vote

@f0o that is correct, you'd need to update Post.user and User.posts. Mongoose doesn't do that for you because the lookup glue is in Mongoose, not MongoDB.

A better alternative would be to store the reference in one place, ideally just User: {type: Schema.Types.ObjectId, ref: "User"}, and make Posts a virtual: https://mongoosejs.com/docs/tutorials/virtuals.html#populate

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@f0o
Comment options

@f0o
Comment options

@vkarpov15
Comment options

@f0o
Comment options

Answer selected by f0o
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants