MongoDB - Filtering returns

0

I would like to know how I can be filtering the results returned in my mongodb queries in this scenario, I will have to return the sector names and contacts for each sector from the company ID, but I would like to return only those records that are marked as active. Here's an example.

    
asked by anonymous 04.09.2017 / 14:35

1 answer

0

I think you are using mongoose, to make nodejs communicate with mongodb, for all queries you make in the database, the first parameter you pass is the json query and the second is the callback . What you can do and spend a second json with the data you want, as in the following example:

db.collection.find(querry,{(funciona igual do mongoshell)})

then your function will look like this in this example:

//
Model.find({_id:/*id qualquer*/}, {ativos: true}, (req, res)=>{
   // sua regra aqui
})
    
05.09.2017 / 14:19