I have a following monogodb collections
coll1 coll2
-------- -------
_id _id
name coll1_ids
coll2 can have multiple reference to coll1 but coll1 will only have one reference
I want to populate coll2 data in coll1. Is there easier way to do it without using aggregation in Node.js.
Thank you!!!
2
Answers
You can use Mongoose
virtual
, you need to definevirtual
in coll1 schema and you can use thosevirtual
inpopulate
like below for examplethen you need to pass that virtual name in Mongoose populate function for example
More clarification about mongoose
virtual
visit this link https://thecodebarbarian.com/mongoose-4.13-virtual-populate-dynamic-refs-fieldsfor speed, you can also use indexing in MongoDB.
and if you use Mongoose for MongoDB connection then you can use Populate also
enter link description here