MongoDB $ oid vs ObjectId

I am trying to run a mongodb request. The collection comes in the format:

{ "_id": { "$oid": "54651022bffebc03098b4567" }, "browser": "ie", "browser_version": "10.0 Desktop", "os_version": "8", "device": null, "os": "Windows" } 

The following works:

 { "_id": { "$in": [ { "$oid": "54651022bffebc03098b4567" }, { "$oid": "54651022bffebc03098b4568" } ] } } 

However, I get a syntax error for the following:

 { "_id": { "$in": [ ObjectId("54651022bffebc03098b4567"), ObjectId("54651022bffebc03098b4568") ] } } 

There are similar questions that suggested ObjectId should work:

How to create a query with ObjectIds using java?

$ all parameters in mongodb do not work with ObjectId list

+6
source share
1 answer

The MongoLab user interface uses Strict MongoDB Extended JSON , therefore Object Identifiers are presented in the same way as in the second block of OP code:

 { "$oid": "<id>" } 
+16
source

Source: https://habr.com/ru/post/978210/


All Articles