How to write a mongo query that queries an array inside an object?

Viewed 80

Lets say I have a mongo database that look like this:

[
  {
    dec: 5972,
    bin: [0,0,0,1,0,1,1,1,0,1,0,1,0,1,0,0]
  },
  {
    dec: 397250,
    bin: [1,1,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,1,0]
  },
  {
    dec: 5,
    bin: [0,1,0,1]
  },
  {
    dec: 123,
    bin: [0,1,1,1,1,0,1,1]
  }
]

How do I query the database to give me all the objects that the number of '0' and '1' in their bin property is equal. For example, I would expect the result to be only:

{
  dec: 5,
  bin: [0,1,0,1]
}       
1 Answers
Related