Let’s say for example i have 2 collections Comments and Users.The comments include username and the comment and Users has username and avatar. When retrieving the comments i also want to display the avatars, how should i query the two collections ? My first thought was to get all the comments and then iterate though the usernames and query the user collection to get the avatars. Can i do this differently ? Using nodejs and mongoose
Let’s say for example i have 2 collections Comments and Users.The comments include username
Share
Populateis likely what you’re looking for:http://mongoosejs.com/docs/populate.html
Pasting some in here for posterity:
ObjectIds can now refer to another document in a collection within our database and be populate()d when querying. An example is helpful: