How to bring all the records of a certain son in mongodb?

Asked

Viewed 133 times

-3

Commando: db.collection.find({"people.name"})

{ 
 "_id" : ObjectId("11111111111111111111111111"), 
 "people" : {
    "name" : "Jose"
  }
}

{ 
 "_id" : ObjectId("222222222222222222222222222"), 
 "people" : {
    "name" : "Willian"
  }
}

{ 
 "_id" : ObjectId("333333333333333333333333333"), 
 "people" : {
    "name" : "Ana"
  }
}

Exit:

{
  "name" : "Jose" 
}
{
  "name" : "Willian" 
}
{
  "name" : "Ana" 
}
  • You can translate to Portuguese from Brazil, after all here is for Brazilians to post their doubts

  • 1

    How to bring all the records of a certain son in mongodb?

  • If you can edit your question and put it all in English, fine?

  • OK I’ll rephrase the question

1 answer

0

After several attempts I managed to solve by myself, you can build the query using the $exists operator.

db.collections.find({ "people": { $exists: true }}, {_id:0, "people.name": 1 })

Browser other questions tagged

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