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 virtual attribute not populating in some cases where populate() is used

I'm trying to populate the job.creator and use the virtual attribute from the User object (user.profile) to give only public information for the job creator. /** * User Schema */ var UserSchema = new Schema({ favorites: { jobs: [{…
chovy
  • 72,281
  • 52
  • 227
  • 295
0
votes
1 answer

Eager Fetch has-many relation using NodeJS/Mongoose

I have following models: LeaderSchema = new app.mongoose.Schema({ email: String, projects: [{ type: app.mongoose.Schema.ObjectId, ref: 'Project'}] }); ProjectSchema = new app.mongoose.Schema({ name: { type: String, required: true}, …
Tomas Romero
  • 8,418
  • 11
  • 50
  • 72
0
votes
2 answers

How to formulate the following Mongoose query?

Here is my schema: var A = new Schema({ active: Boolean , containers: [{ b: { type: ObjectId, ref: 'B' } }] }) var B = new Schema({ c: { type: ObjectId, ref: 'C' } , d: { type: ObjectId, ref: 'D' } }) var C = new Schema({…
fusio
  • 3,595
  • 6
  • 33
  • 47
0
votes
1 answer

mongoose sub populate not works

here is my schema : var sourcesSchema = { title: String, name: String, url: String, description: String, category: Array, rating: Number, source_pages: [{ type: mongoose.Schema.Types.ObjectId, ref:…
Sina Miandashti
  • 2,087
  • 1
  • 26
  • 40
-1
votes
1 answer

Is it possible to query by populate document in Mongoose

I also tried in mongoose doc and MongoDB community but I couldn't find any solution.
-1
votes
1 answer

How to use populate, within select, in MongoDB?

Suppose I have two schemas on MongoDB: const personSchema = Schema({ _id: Schema.Types.ObjectId, name: String, email: String, things: [{ type: Schema.Types.ObjectId, ref: 'Thing' }] }); const thingSchema = Schema({ _id:…
jessl
  • 1
  • 1
-1
votes
1 answer

How to query specific values from a two level Mongoose populate?

I would like to query specific values from a two level Mongoose populate. const {_id, name, email, role, account, subUsers } = await User.findById(req.user.id) .populate({ path : 'account', // need specific values from this…
-1
votes
2 answers

Retrieve object information within an array with mongoose

I'm making an API Rest with node, express, typescript and mongoose. I have a method GET that return this result: { "success": true, "status": 200, "message": "categories listed", "data": [ { "_id": "612650e55fe1ce0de138e2af", …
-1
votes
1 answer

mongoose.populate() is not showing populate content

// my user schema const mongoose = require('mongoose'); const {ChatRoom} = require('./chatRoom'); const userSchema = new mongoose.Schema({ _id: mongoose.Schema.Types.ObjectId, username:{ type: 'String', unique: true, }, collegeEmail:{ …
RK NANDA
  • 71
  • 8
-1
votes
1 answer

mongoose schema inner join not getting result in my case

i am following many example of mongoose for inner join with schema but not getting response my other tables. my question is what is missing in my code please help me this. i want getting result of class and subjects also. …
Addi Khan
  • 85
  • 1
  • 3
  • 12
-1
votes
1 answer

Mongoose populate how to get populate document in same object instead of sub document

I am using mongoose populate for getting another documents.I am getting data but as sub document instead of sub document how can i get in same object. { "key":"value" "userid":{ _id:"userid" } } but i need to get like…
j dileep
  • 505
  • 1
  • 4
  • 11
-1
votes
2 answers

Mongoose populate function not working after .find()

I am trying to query out multiple user profiles and then populate each one of the profiles and send it to the client side of my web application. But it's failing miserably. I have done my research and tried everything but it still won't populate it.…
-1
votes
1 answer

Function returning undefined instead of a Number

I have a function in js which is basically computing a bill. Here is The code :- let bill = () => { Customer .findOne({stb_no: "34BDFA64E31F"}) .then(result => { Plan.findById(result.plan).populate('channel_list').exec(function(err,…
-1
votes
1 answer

how to use mongoose refs to handle one-to-many relation

I have two schemas just as the following Student.js module.exports = (mongoose) => { const Schema = mongoose.Schema; const studentsSchema = new Schema({ name : { type : String, required : true }, roll : { type :…
-1
votes
1 answer

How to use different types of References and populate

So i have two schemas, Article and Event Both have an image field. For Article, featured_image: { type: String, default: '', } For Event, featured_image: { type: Schema.ObjectId, ref: 'Medium' } I have another schema, Card, like…
1 2 3
68
69