pythondjangomongodbdjongo

Filter mongo document in django


The project stack is Django + MongoDB (djongo library).
I have product table with data structure like this

{
  _id:"qwer1234",
  organization:{...},
  service:{
      "id":1,
      ...
 
  }
}

How can I get all documents where service.id will be in array of id ([1,2,3])?


Solution

  • Simply use $in like this:

    db.collection.find({
      "service.id": {
        "$in": yourArray
      }
    })
    

    Check this example