What is the best way to find all the documents where objA is the same as objB (order of keys is not important)?
Inspired by another question by @Digvijay, I was looking for a way to compare two objects on MongoDB query and could not find a relevant solution on SO.
Sample data:
[
{
objA: {a: 1, b: 2},
objB: {a: 1, b: 2}
},
{
objA: {m: "g", c: 5},
objB: {c: 5, m: "g"}
},
{
objA: {m: "g", c: 7},
objB: {c: 5, m: "g"}
},
{
objA: {m: "g", c: 7},
objB: {b: "g", c: 7}
}
]
Expected results:
[
{
objA: {a: 1, b: 2},
objB: {a: 1, b: 2}
},
{
objA: {m: "g", c: 5},
objB: {c: 5, m: "g"}
},
]