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 user interface

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -