mongoose-populate

how can I rewrite my mongoose query after splitting data from one model into two?

元气小坏坏 提交于 2019-11-30 20:31:08
问题 In my application I store comments. Previously my model for that looked like this: var CommentsSchema = new Schema({ username: {type: String}, display_name: {type: String}, facebook_username: {type: String}, text_content: {type: String}, photo_content_url: {type: String}, hashtags: {type: [String]}, device_id: {type: String}, comment_date: {type: Date, default: Date.now}, friends_only: {type: Boolean, default: false} } Each comment - besides storing its details - had also details about the

Mongoose Populate after Aggregate

半腔热情 提交于 2019-11-30 15:30:51
I am trying to get a specific data model after I run an aggregate pipeline followed by populate but I am falling just short of it. The desired result in the end is the following: [ { _accountId: "5beee0966d17bc42501f1234", name: "Company Name 1", contactEmail: "email1@email.com", contactName: "contact Name 1" reason: "Warranties", total: 1152, lineItems: [ { _id: "5beee0966d17bc42501f5086", jobsiteAddress: "1234 Street Southwest Sunnyville, Wyoming 12345", warrantyFee: 384 }, { _id: "5bf43929e7179a56e21382bc", jobsiteAddress: "1234 Street Southwest Sunnyville, Wyoming 12345", warrantyFee: 384

what does populate in mongoose mean?

江枫思渺然 提交于 2019-11-30 13:54:23
I came across the following line of code which I couldn't understand ,although there are lot of tutorials that gives information related to examples of populate but there is none that explains what exactly it means.Here is a example var mongoose = require('mongoose'), Schema = mongoose.Schema var PersonSchema = new Schema({ name : String, age : Number, stories : [{ type: Schema.ObjectId, ref: 'Story' }] }); var StorySchema = new Schema({ _creator : { type: Schema.ObjectId, ref: 'Person' }, title : String, fans : [{ type: Schema.ObjectId, ref: 'Person' }] }); var Story = mongoose.model('Story',

Multiple schema references in single schema array - mongoose

╄→гoц情女王★ 提交于 2019-11-28 18:54:59
Can you populate an array in a mongoose schema with references to a few different schema options? To clarify the question a bit, say I have the following schemas: var scenarioSchema = Schema({ _id : Number, name : String, guns : [] }); var ak47 = Schema({ _id : Number //Bunch of AK specific parameters }); var m16 = Schema({ _id : Number //Bunch of M16 specific parameters }); Can I populate the guns array with a bunch of ak47 OR m16? Can I put BOTH in the same guns array? Or does it require a populate ref in the assets array, like this, which limits it to a single specific type? guns: [{ type:

Mongoose populate nested array

霸气de小男生 提交于 2019-11-28 05:27:48
Assuming the following 3 models: var CarSchema = new Schema({ name: {type: String}, partIds: [{type: Schema.Types.ObjectId, ref: 'Part'}], }); var PartSchema = new Schema({ name: {type: String}, otherIds: [{type: Schema.Types.ObjectId, ref: 'Other'}], }); var OtherSchema = new Schema({ name: {type: String} }); When I query for Cars I can populate the parts: Car.find().populate('partIds').exec(function(err, cars) { // list of cars with partIds populated }); Is there a way in mongoose to populate the otherIds in the nested parts objects for all the cars. Car.find().populate('partIds').exec

Mongoose populate nested array

无人久伴 提交于 2019-11-27 00:56:58
问题 Assuming the following 3 models: var CarSchema = new Schema({ name: {type: String}, partIds: [{type: Schema.Types.ObjectId, ref: 'Part'}], }); var PartSchema = new Schema({ name: {type: String}, otherIds: [{type: Schema.Types.ObjectId, ref: 'Other'}], }); var OtherSchema = new Schema({ name: {type: String} }); When I query for Cars I can populate the parts: Car.find().populate('partIds').exec(function(err, cars) { // list of cars with partIds populated }); Is there a way in mongoose to