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
3
votes
0 answers

Mongoose Populate when using ObjectId not working

New to mongoose! I want to get all orders and populate each order with the product schema. However when I test the route no information comes through when I have the products type as ObjectId. How can I find all orders , populate the order with its…
3
votes
0 answers

not able to filter an nested record in find method and in populate method together

i am trying to filter out a nested record based on my searchKey .for Example: patient - >provider want to search a patient and an provider together based on searchKey. But when i'm triggering searchkey with patient details it's working but when i…
3
votes
1 answer

Is it possible to convert a buffer to base64string in populate mongoose?

I have a mongoose Image Schema as below: const ImageSchema = new mongoose.Schema({ img: { data: Buffer, contentType: String } }) mongoose.model('Image',ImageSchema) and a Chapter schema const chapterSchema = new…
pixy
  • 61
  • 9
3
votes
3 answers

Why is execPopulate method required in mongoose for populating an existing document?

I know the syntax of it and how it works, but I cannot understand the internal workings, why does a method chaining require another method at one time, but doesn't some other time? This code works fine const cart = await…
Gaurav
  • 98
  • 3
  • 13
3
votes
1 answer

Mongoose/Express population issue

Here are my schemas: 1.The Records schema: const mongoose = require('mongoose') const RecordsSchema = new mongoose.Schema({ Title: { type: String, required: true }, postedby: [{ type: mongoose.Schema.Types.ObjectId, ref:…
3
votes
1 answer

Populate subdocument array field with Mongoose

I know this question has been asked before, but after hours of research I have tried several ways to solve my problem without success. Schema const ValuationsSchema = new Schema( { value: { type: Number, required: true, min: 0,…
Raul Mabe
  • 453
  • 5
  • 15
3
votes
2 answers

How to search in Mongoose populate array [array containing ref]

I'm new in MEAN stack development. Please anyone tell how to search in Mongoose populate array. that array containing ref. Discussion Schema: const discussionSchema = new Schema({ user_id: { type: mongoose.Schema.Types.ObjectId, ref:…
Gautam Sharma
  • 303
  • 1
  • 10
3
votes
1 answer

NestJS + Mongoose + GraphQL : "populate" not working

thanks for the great framework! I use mongoose with GraphQL and have the following problem: If I want to resolve the ObjectIDs stored in the array "arguments" of a user with populate, in GraphQL I get the user with an empty arguments array as…
stoniemahonie
  • 321
  • 1
  • 5
  • 13
3
votes
1 answer

In mongoose Populate ref to other field instead of _id, reference to custom field not _id

userSchema={ username: { type: String, required: true, unique: true }, password: { type: String, required: true }, role: { type: String } } influencerSchema={ user_id: { type: Schema.Types.ObjectId, ref:…
3
votes
1 answer

Mongoose fails to populate virtual when foreignField is an Array

I'm trying to create a virtual populator in mongoose, but I'm stumped on this aspect, and I don't know if this is a limitation, a bug, or simply I'm doing something wrong. The idea is that a user can be member of several groups, and then I can…
Stormbolter
  • 203
  • 2
  • 7
3
votes
1 answer

Populate from One Model to Another Using Mongoose/MongoDB in Node/Express Application

I am struggling to understand the populate method in Mongoose, while having trouble populating fields from one Mongoose model to another. The first model Schema is: var MprnSchema = new mongoose.Schema({ mprNo: {type: Number, unique: true,…
ASTIN77
  • 125
  • 8
3
votes
0 answers

Populating nested objects in mongoose/node.js

I have a Model as shown below and I'm trying to do a populate in a get route. (I also have a List model that is linked to this model using ref). var listItemSchema = mongoose.Schema({ text: String, url: String, bought:Boolean, …
3
votes
3 answers

Mongoose document.populate() is not working

I am using a pretty simple Node/Mongo/Express setup and am trying to populate referenced documents. Consider my schemas for "Courses" which contain "Weeks": // define the schema for our user model var courseSchema = mongoose.Schema({ teachers …
dcoffey3296
  • 2,504
  • 3
  • 24
  • 34
3
votes
0 answers

Mongoose: find all docs where _Id of nested sub-doc in array matches userId

an abbreviated schema: const ThingSchema = new mongoose.Schema({ _id: { type: String, }, widgets: [{ user: { type: Schema.Types.ObjectId, ref: 'user', }, lastViewedAt: { type: Date, }, }], }, { _id:…
Jadam
  • 1,650
  • 1
  • 19
  • 40
3
votes
1 answer

Populate Only When Conditions Are Met

I have a mongodb database and I use mongoose with nodejs. I need return data from the next query populating "tabela_tuss" only if I have the field "temtussvinculado=true". Here is what I am doing: ConvProced.find({'convenioId':new…
Luiz Alves
  • 2,575
  • 4
  • 34
  • 75