express-mongoose-es6-rest-api
express-mongoose-es6-rest-api copied to clipboard
How to Join these two documents for API calls
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,
});
@Ramakrishnatp see http://mongoosejs.com/docs/populate.html