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
1 answer

mongoose How to exclude _id from populated

I am populating _group in my role document return this.find(query, {'_group': 1, 'name':1, 'description': 1} ) .populate('_group', ['name', 'description']) .sort({ createdAt: -1 }) ... I get also the _id of the…
user762579
3
votes
1 answer

mongoose query low performance when using with populate

I need help with this query. I am querying 8000 documents in AppVisitorwith 4 collections populated.But it is not returning any result. Means it get stuck and after some time nodejs server return 404 error for route in which this query is…
Abhishek Singh
  • 1,631
  • 1
  • 17
  • 31
3
votes
1 answer

Mongoose - null references removed by populate?

I have a problem I can't figure out how to solve. I've got a Mongoose model which contains an array of references, which are to be populated. Something like this: new mongoose.Schema( { arr: [ { type: mongoose.Schema.Types.ObjectId, ref:…
TheHult
  • 31
  • 1
  • 2
3
votes
1 answer

Mongoose Populate with API request and Postman, return empty array?

I have created an api with nodejs, mongodb/mongoose and express, to make CRUD request to interact with json data, more specifically, with two mongodb collections (1: datas 2: produits). The "datas" collection is bind to an "User" schema. The…
amalrik
  • 31
  • 1
  • 6
3
votes
0 answers

Use calculated fields to calculate new field in $project with MongoDB

I have a collection Item with fields _id, price, and project as well as a collection Project with fields _id and name. The items have different prices, so I want to group the items by price and count how many items are in each group and save the…
Jamgreen
  • 10,329
  • 29
  • 113
  • 224
3
votes
2 answers

deep populating in mongoose

I've got two schemas, one for user and another one for post in the user schema, I've got a property for latestPost which would be an ObjectId of an entry in the post schema when I load up the user object, I want to get the lastestPost as an object…
totalnoob
  • 2,521
  • 8
  • 35
  • 69
3
votes
1 answer

MongoDB/Mongoose One-to-Many with refence to parent in child - group and join

I followed the suggestion in Mongo docs to have Parent & Child collections with reference to parent in the child collection as the child collection has the prospect to…
user1220169
  • 805
  • 2
  • 9
  • 14
3
votes
2 answers

(Mongoose) How to get user._id from session in order to POST data including this user._id

I am new in Mongoose. I'm developing a MEAN stack To do list with user authentification. (In other words, a user can register login and create, get, update and delete the to do's). It means 2 schemas: 'users' and 'tasks' With a relationship one to…
3
votes
1 answer

Mongoose select,populate and save behaving differently on Mac and Windows

Here's what i did static populateReferralLinks(){ return Promise.coroutine(function*(){ let companies = yield Company.find({},'billing referral current_referral_program') …
Devesh Jadon
  • 7,004
  • 4
  • 22
  • 27
3
votes
3 answers

Clean up dead references with Mongoose populate()

If a user has an array called "tags": var User = new Schema({ email: { type: String, unique: true, required: true }, tags: [{ type: mongoose.Schema.Types.ObjectId, ref:'Tag', required:…
Garett
  • 552
  • 6
  • 15
3
votes
3 answers

Mongoose populate with match condition for nested document

I have a mongoose schema like this: var Address = { doorNo:String, city:String, state:String, country:String, district:String, zipCode:String, area:String, locality:String }; var StoreSchema = { name:String, …
Puneet
  • 654
  • 1
  • 8
  • 16
3
votes
1 answer

mongoose populate nested array with condition for array element

I have an ArticleGroup which contains articles, models look like this var ArticleGroup = new mongoose.Schema({ articles:[{type:mongoose.Schema.Types.ObjectId,ref:'Article'}] }) var Article = new mongoose.Schema({ rates:[{ …
Yangxiao Ou
  • 115
  • 6
3
votes
1 answer

Mongoose populate not populating

I am trying to populate my users car inventory. All the cars have a userId attached to them when they are created but when I go to populate the inventory it doesn't work and I get no errors. Here are my models: User.js let UserSchema =…
3
votes
1 answer

How can I deep populate multiple paths in mongoosejs?

Is it possible to simultaneously populate multiple paths using mongoose? I am trying to do something like this: User.findById(_id) .populate({ path:'friendIds', model:'User', populate: { path: 'reviewIds', model: 'Review', …
devigner
  • 152
  • 12
3
votes
2 answers

Mongoose remove subdocuments by id method

I have two models: var mongoose = require('mongoose'); var Schema = mongoose.Schema; var ProjectSchema = new Schema({ title: { type: String }, images: [{ type: Schema.Types.ObjectId, ref: 'Image' }] }); module.exports =…
Jordy Bulten
  • 155
  • 1
  • 1
  • 9