How to use mongoose aggregate well

DD DD

I am using this query search with Mongodb to get only '_id' value matched from 'clientID'.
It works well at roto3T.

db.getCollection('orders').find({"clientID":"1234"}, {$_id:true});

But I want to use this at mongoose. So I put like below.
But It doesn't work well. How can I make the query search well in Mongoose? Thank you so much!

await Order.find({ clientID: { $_id: true },},
    (error, order) => {
      if (error) {
         return next(error);
      }
      return res.send({order,});
},);
Naing Lin Aung

if you want to use Async Await,

try {    
    let order =  await Order.find({"clientID":"1234"}, "_id"); 
    return res.send({order});
} catch(error) {
    return next(error);
}

or otherwise if you want to use callback

 return Order.find({clientID:"1234" },{ '_id': 1 },(error,order) => {
     if (error) return next(error);
     return res.send({order});
 });

You can't use both to retrieve your data

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

TOP Ranking

HotTag

Archive