1

i have this data from a MongoDB database, i want to return all the objects from the array "Books" and how to query for a specific book inside this array ?

{
  "_id": {
    "$oid": "5b193757fb6fc05a6fe42330"
  },
  "Books": [
    {
      "Me Talk Pretty One Day ": {
        "_id": 312
      }
    },
    {
      "One Hundred Years of Solitude ": {
        "_id": 123
      }
    }
  ]
}
Ashh
  • 44,693
  • 14
  • 105
  • 132
Bruno Cerk
  • 355
  • 3
  • 16

1 Answers1

1

If you want to retrive specific book from the array you can try this

db.collection.find({
  Books: {
    $elemMatch: {
      "Me Talk Pretty One Day": {
        $exists: true
      }
    }
  }
},
{
  Books: {
    $elemMatch: {
      "Me Talk Pretty One Day": {
        $exists: true
      }
    }
  }
})
Ashh
  • 44,693
  • 14
  • 105
  • 132