Using MongoDB/Mongoose, consider my test
collection having the following 2 documents:
"_id" : ObjectId("5c4e3cef9cd12904cfc7ecc0"),
"name" : "REGISTER1",
"properties" : [
{
"property” : "PROP1",
"value" : "GREEN"
},
{
"property” : "PROP2",
"value" : "RED"
}
]
and
"_id" : ObjectId("5c4e3cef9cd12904cfc7ecc0"),
"name" : "REGISTER2",
"properties" : [
{
"property" : "PROP2",
"value" : "RED"
},
{
"property" : "PROP1",
"value" : "GREEN"
}
]
I'm using the folowing commands to find the registers:
db.tests.find(
{ properties: [
{
"property" : "PROP2",
"value" : "RED"
},
{
"property" : "PROP1",
"value" : "GREEN"
}
]
}).pretty();
That returns REGISTER2
, not REGISTER1
.
In the same way:
db.tests.find(
{ properties: [
{
"property" : "PROP1",
"value" : "GREEN"
},
{
"property" : "PROP2",
"value" : "RED"
}
]
}).pretty();
That returns REGISTER1
, not REGISTER2
.
I need both queries to return both elements 'REGISTER1' and 'REGISTER2', as the only change between then is the properties order (the array order).
How can I query to return both REGISTER1
and REGISTER2
, no matter the array order of the query elements ?
property_id
and on second document property key isproperty
– Saravana