express-mongoose-es6-rest-api icon indicating copy to clipboard operation
express-mongoose-es6-rest-api copied to clipboard

How to Join these two documents for API calls

Open ghost opened this issue 7 years ago • 1 comments
trafficstars

City Document : { "_id" : ObjectId("555ec317e6e8ce4e0d3c2541"), "state" : ObjectId("54f91ea29f2e20e67d61ba6c"), "deleted" : false, "created" : ISODate("2015-05-22T05:48:07.831Z"), "description" : "", "name" : "Hydrabad", "__v" : 0 }

State Document: { "_id" : ObjectId("54e461ef7214e6583c0c5ed5"), "__v" : 0, "created" : ISODate("2015-02-18T09:57:03.585Z"), "deleted" : false, "description" : "", "name" : "Andhra pradesh", "updated" : ISODate("2016-10-09T18:20:29.601Z") }

Schemas : StateSchema = new Schema({ _id: { type: String }, statename: { type: String, required: true, max: 50 }

})

CitySchema = new Schema({ id: mongoose.Schema.Types.ObjectId, name: { type: String, required: true, max: 50 },

statename: { type:String, ref: 'State' ,field: 'state'}, deleted: Boolean,

});

ghost avatar Mar 07 '18 18:03 ghost

@Ramakrishnatp see http://mongoosejs.com/docs/populate.html

gianpaj avatar Mar 23 '18 16:03 gianpaj