Questions tagged [mongoose-populate]

The Mongoose ODM has a populate() feature which lets you reference related documents in other collections. Mongoose can populate a single document, multiple documents, plain object, multiple plain objects, or all objects returned from a query.

MongoDB 3.2+ servers include a $lookup aggregation feature which enables joining query results from multiple collections in the same database.

The Mongoose ODM provides a client-side alternative called populate(), which lets you reference related documents in other collections (including those in different databases).

Population is the process of automatically replacing the specified paths in the document with document(s) from other collection(s). Mongoose can populate a single document, multiple documents, plain object, multiple plain objects, or all objects returned from a query.

Related Links

1023 questions
0
votes
2 answers

Mongoose one has many relations between Schemas

I know that this question has been raised many times before and that Mongo doesn't have that exact "has many" connection, but I failed to make connections between two schemas so far. Here is what I have: User model (user.js) var userSchema =…
vitalym
  • 893
  • 6
  • 12
  • 29
0
votes
1 answer

Finding a referenced document in all the existing collection using Mongoose

I have 3 collections : events : { _id: ObjectId(54ca0f2506d0c6b673b2fde8), _reference: ObjectId("54fd786c549e96f70f9c027d") }, { _id: ObjectId(54acd81941a646d768922cfa), _reference: ObjectId("54fd786c549e96f70f9c027d") } posts : { …
0
votes
1 answer

Mongoose populate specific array instance

I tried lot of combination didnt work out so need your help. Consider your have a document schema and versions var VersionSchema = mongoose.createSchema("version", { version: { type: Number}, metadata: { type: Schema.Types.ObjectId, ref:…
0
votes
2 answers

Mongoose populate list of references

Mongoose (v3.8) + Node.js I have a model called 'Products' which has this field: upvoted_by: [{ user_id: { type: Schema.ObjectId, ref: 'Users' }, timestamp: { type: Date } }] And the Users model has a bunch of other fields. To add an…
KGo
  • 18,536
  • 11
  • 31
  • 47
0
votes
1 answer

MongooseJS populate using multiple target fields

I have the following two Schemas: var MessageModel = mongoose.model("message", new Schema({ sender:{type:ObjectId,ref:"user"}, recipient:{type:ObjectId,ref:"user"}, title: String }) ); var UserModel =…
srfrnk
  • 2,459
  • 1
  • 17
  • 32
0
votes
1 answer

mongoose saving a model with a reference

I have a model that looks something like this var UserSchema = new Schema({ id: ObjectId, username: { type: String, trim: true, required: true, unique: true, lowercase: true }, location: [{ type:…
gmaniac
  • 940
  • 1
  • 17
  • 33
0
votes
1 answer

Moogoose self reference not populate

I have a self reference in mongoose like this : var wordSchema = new mongoose.Schema({ content : String, country: [{type: mongoose.Schema.Types.ObjectId, ref: 'Country'}], trad: { words: [{ _id: {…
user3653664
  • 37
  • 10
0
votes
2 answers

Can't make populate in mongoose returning null

Im trying to create a FoodItem Schema In which i kept measureUnit as an object reference from another page's model. This is MeasureTypesSchema where the measureUnit is present. MeasureTypes is a embedded array document inside MetricsSchema. I am…
SUNDARRAJAN K
  • 2,237
  • 2
  • 22
  • 38
0
votes
1 answer

Mongoose dynamic models, cannot use populate()

My CMS is written in Node.js + Express + Mongoose. It's a multisite CMS and each site has its own database. So I needed to make Mongoose to switch the connection at every HTTP request. I looked around for some solution, or someone who had my same…
Darko Romanov
  • 2,776
  • 2
  • 31
  • 38
0
votes
2 answers

Mongoose populate issue - array object

My schema is as below Sectionschema var SectionSchema = new Schema({ name: String, documents : { type : [{ type: Schema.ObjectId, ref: 'Document' }] } } } DocumentSchema var DocumentSchema = new…
sabari
  • 2,595
  • 5
  • 28
  • 44
0
votes
0 answers

Cast to ObjectId failed for value "[object Object]" at path "e"

The below is my schema var a = new Schema({ d: { type: Schema.ObjectId, ref: 'Student' }, e: { type: Schema.ObjectId, ref: 'Student' }, f: { type: [{ type: Schema.ObjectId, ref: 'Exam' }], select:…
sabari
  • 2,595
  • 5
  • 28
  • 44
0
votes
2 answers

Populating nested array with ObjectIDs

Trying to populate an array of ObjectID's within my schema. I've looked around at similar answers but it seems everyone is doing it slightly differently and I haven't been able to find a solution myself. My schema looks like this: var GameSchema =…
jket
  • 418
  • 6
  • 9
0
votes
2 answers

How can I populate friends of current user in meanjs?

I want to display friends of Authenticated user in angularjs page. // Find a list of Friends $scope.find = function() { $scope.friends = Authentication.user.friends; $scope.firstFriendName = Authentication.user.friends; …
Emre Alparslan
  • 1,022
  • 1
  • 18
  • 30
0
votes
1 answer

Manipulating ref'd mongo records based on _id field

Ok so I have a pretty simple DB setup in a MEAN app (node, mongoose, mongo) where I have Book records, and User records. A book has a single Owner, and can have any number of shared users which are stored in an array in a field called sharedWith:. …
Askdesigners
  • 419
  • 5
  • 15
0
votes
1 answer

how to retrieve other details of a schema based on the reference key

I have a project am working on. I have a comment schema, a likes schema and a blog schema. All three are declared as separate schemas but the likes and comments schema are then nested into the blogs schema as children i.e comments: [CommentSchema].…
user3775998
  • 1,393
  • 3
  • 13
  • 22