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
10
votes
2 answers

Mongoose multiple deep populates

Say, I have Manager schema: { name: { type: String }, clients: [{ type: Mongoose.Schema.ObjectId, ref: 'Client'}] } And, I have Client schema: { name : { type String }, cars : [{ type: Mongoose.Schema.ObjectId, ref: 'Car' }], …
wscourge
  • 10,657
  • 14
  • 59
  • 80
10
votes
1 answer

mongoose : Could we populate reference object to a alias/virtual property?

I'm looking for a way to populate to a alias/virtual property using mongoose ? For now, mongoose's population is add more fields to the reference property (normally is the identity key). I want to keep my original property and populate the…
pham cuong
  • 849
  • 1
  • 12
  • 24
9
votes
2 answers

MongoDB populate performance

Recently asked such a question. What is faster in Mongo: a populate or individual assync requests? Example var mongoose = require('mongoose') , Schema = mongoose.Schema; var FeedPostCommentSchema = new Schema({ feedPost: {type:…
Ashot
  • 245
  • 6
  • 16
8
votes
2 answers

Mongoose - Cannot populate with sort on path notifications.from because it is a subproperty of a document array

I have a very simple mongo scheme I'm accessing with mongoose I can map the username and firstname to each notification's from field by using populate, the issue is I can't seem to get any sorting to work on the date field With this code I get an…
totalnoob
  • 2,521
  • 8
  • 35
  • 69
8
votes
1 answer

Mongoose populate across 2 databases

I have a node app that uses 2 databases. One is the the Names and the other for the rest of all the data. I have this connection setup: // DATABASE CONNECTION var APP_DB_URI = config.APP_DB; // mongodb://localhost:27017/app_db var app_DB =…
jofftiquez
  • 7,548
  • 10
  • 67
  • 121
8
votes
1 answer

How to register and use mongoose-deep-populate

okay. so I'm trying to do some nested population of my mongoose models. And I found that Mongoose-Deep-Populate was one of the easiest fixes for the nested solution, however, as easy as it might seem, I can't figure out how to register the plugin…
Michael Tot Korsgaard
  • 3,892
  • 11
  • 53
  • 89
7
votes
0 answers

mongoose: Populating a discriminated subdocument

I want to populate the fields of a subdocument, which is a discriminated element of a common Schema (Notificationable discriminated into Message or FriendRequest). This question is quite similar to this one: mongoosejs: populating an array of…
7
votes
3 answers

Mongoosejs - Filter out populate results

I want to return all chat conversations, where the logged in user (user_id) is a participant. I want to populate the participants only returning the profile.firstname (maybe some other later), i then want to filter out the participants so that it…
Kay
  • 339
  • 2
  • 7
  • 16
7
votes
2 answers

How to populate documents with unlimited nested levels using mongoose

I'm designing a web application that manages organizational structure for parent and child companies. There are two types of companies: 1- Main company, 2 -Subsidiary company.The company can belong only to one company but can have a few child…
6
votes
2 answers

Why does mongoose populate virtual field as array instead of single item?

I want to populate an object into a virtual field with mongoose as a JSON object, but it always returns an array with a single item. Here is my scheme code (part with virtual field): Order.virtual('client', { type: 'ObjectId', ref: 'User', …
6
votes
1 answer

How to exclude null values from Mongoose populate query

I am building an app and I have create 2 models. const UserSchema = new Schema({ _id: Schema.Types.ObjectId, account:{ type: String, unique: true }, email: String, first_name: String, last_name: String } …
6
votes
1 answer

Mongoose: Filter collection based on values in another collection

Consider documents that contain an arrays of ID of another collection, how can I find documents applying a filter based on the related collection using mongoose? I can't find my error Installation.aggregate( …
Gelso77
  • 1,763
  • 6
  • 30
  • 47
6
votes
1 answer

Mongoose: How can I access a populated field from a virtual getter?

I have a couple Schemas: var parentSchema = new Schema({name: String}); var childSchema = new Schema({ name: String, parent: {type: Schema.ObjectId, ref: 'Parent'} }); I want to be able to call Child.find().populate('parent') and then use…
6
votes
0 answers

populate mongoose key as part of object

EDIT minimal reproduction repo It's easier to explain in code than English. The following code works, but it feels like there's gotta be an easier, more MongoDBy/mongoosy way ... // recipeModel.js, relevant part of the schema equipments: [{ _id:…
6
votes
2 answers

login with email or username with MongoDB in Node.js

I am wondering if there is a way to let user to login with both username or email I searched a lot of times for but doesn't found a working method. I don't have a single idea how to do this, please help with the easiest way if possible. here is what…
Zub
  • 808
  • 3
  • 12
  • 23
1
2
3
68 69