0

I have a collection named Teachers on MongoDB with some documents, here is an example:

{
"_id" : ObjectId("63a89cdae570d47034c996ec"),  
"teachingCategories" : [ 
    [ 
        ObjectId("63a40c7e54351f6071b25abd"), 
        ObjectId("63a65195075c0031b1bd2e81")
    ], 
    [ 
        ObjectId("63a40b4654351f6071b25a82"), 
        ObjectId("63a41d5d54351f6071b25acf"), 
        ObjectId("63a44bdc54351f6071b25b9a")
    ], 
    [ 
        ObjectId("63a40c7e54351f6071b25abd"), 
        ObjectId("63a651d6075c0031b1bd2e87")
    ]
]

}

i am trying to find the teachers who have the category id like below

db.collection("teachers").find({ teachingCategories: ObjectId("63a44bdc54351f6071b25b9a") })

but the mongo db returns nothing

0

1 Answer 1

1

As the teachingCategories in your document is arrays in array you can try something like this

db.teachers.find({
  teachingCategories: {
    $elemMatch: {
      $elemMatch: {
        $in: [ObjectId("63a44bdc54351f6071b25b9a")]
      }
    }
  }
})

Similar question to Querying an array of arrays in MongoDB

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.