node.js - Mongoose population on field other than _id (eg. String name) -
i trying populate reference field not correspond id of model referencing.
for example code
var locationschema = new schema({ name: {type: string, default: "location"}, location_id: {type: number, default: 0}, drones: [{ type: string, ref: 'drone' }], }); locations contain array of drone names, names unique.
i setup location , push strings onto drones array.
location.drones.push('test4'); location.save(); when go populate
location. findone({}). populate('drones', 'name'). i error
"message": "cast objectid failed value \"test4\" @ path \"_id\" model \"drone\"", my question how populate field such (string) name, instead of _id?
Comments
Post a Comment