Equal to condition in array is accurate?

I have a scenario where i need to match the full array, there are only 2 elements in array, for Ex:

[
  { field: [1,2] },
  { field: [5,6] },
  { field: [2,1] }
]

The below query works fine, It will results first document,

.find({ field: [1,2] })

I have to confirm is it 100% accurate? Will it fail like if it returns the third document that is [2,1]?

Hi @turivishal ,

I think this equation can guarantee order and size.

I think you need to also be aware of $all opertor to guarantee all elements exists.

Thanks
Pavel

1 Like

Thank you for your reply,

I need to check order of elements as well,

  • valid (for my example)
[1,2] = [1,2]
  • invalid (for my example)
[1,2] = [2,1]

So $all will not work for my situation,

Thanks for your confirmation, i will use equal to condition.