Mongodb - Filtering returns

Asked

Viewed 231 times

0

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

inserir a descrição da imagem aqui

1 answer

0

I believe you are using Mongoose, to make the nodejs communicate with mongodb, for this all the queries you make in the database, the first parameter you pass is the json query, and the second is callback. What you can do and pass 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 in this example:

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

    Tip: Don’t use abbreviations or slang in your answers.

  • Vlw, although what is worth and the content, and not the writing form!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.