node.js - Mongoose find all documents with a given ObjectId -
I have a photo model and each picture has a vehicle associated with it:
Var object id = mongoose Sema Object ID; Var photoSchema = mongoose.Schema ({name: {type: string}, path: {type: string}, vehicle: {type: object, ref: 'vehicle'}}); What can I do to return all the photos matching the given vehicle _id ? I think the query looks like a normal search, but I'm not sure how to convert _id into an ObjectId.
You do not have to change anything, your ObjectId The same is _id but in the string format when you send it anywhere via JSON try the following: Photo.find ({Vehicle: id}, function (fault, result) {...}); above id is just your vehicle 's
Comments
Post a Comment