[SERVER-56139] JSON based query to identify if there are any other field present apart from provided one Created: 16/Apr/21  Updated: 16/Apr/21  Resolved: 16/Apr/21

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Critical - P2
Reporter: Hitesh Baldaniya Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-56138 JSON search if any other key present ... Closed
Participants:

 Description   

Hi Team,

We are working on the following case where we need the confirmation of the behaviour.
 
let's consider the following example,where "test" json object will have keys.
{
"_id": ObjectID('123'),
"test":

{ "a":1, "b":1 }

},
{
"_id": ObjectID('456'),
"test":

{ "a":1 }

We wanted to filter all the documents where "test" json does have any key other than `"a": 1`.
 
So, we went to search for the solution and tried the following, which provided the expected result. We also put the index on the "test" field to avoid any performance issues and it worked as well.
db.col.find({"test": {"$gt":

{"a": 1}

}})
 
But did not find any such query or case on MongoDB official site, so just looking out for the support that this is a proper solution and there is no downside to it.

Thanks,


Generated at Thu Feb 08 05:38:28 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.