# Any way to query apoc.mongodb.find by ObjectId

**URL:** <https://community.neo4j.com/t/any-way-to-query-apoc-mongodb-find-by-objectid/32523>\
**Category:** Procedures & APOC\
**Tags:** apoc, mongodb, cypher\
**Created:** [January 22, 2021, 6:28pm UTC](https://community.neo4j.com/t/any-way-to-query-apoc-mongodb-find-by-objectid/32523 "2021-01-22T18:28:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![enstricht](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/enstricht/32/7487_2.png) [@enstricht](https://community.neo4j.com/u/enstricht)\
**Post date:** [January 22, 2021, 6:28pm UTC](https://community.neo4j.com/t/any-way-to-query-apoc-mongodb-find-by-objectid/32523/1 "2021-01-22T18:28:06Z")

</div>

The documents in m MongoDB have a \_id of type ObjectId. In Neo4j a node has a reference to the document by the ObjectId as a string representation. But i can´t figure out how to query a document by the ObjectId as a string using apoc.mongodb.

Neo4j 4.2.1 community and APOC (+ mongodb driver) 4.2.0

This obviously does not work:

`CALL apoc.mongodb.find("mongodb://host:port", "testdb", "testcoll", {_id: "6005c050d36d9acd28b8679b"}, null, null)`  
`CALL apoc.mongodb.find("mongodb://host:port", "testdb", "testcoll", {_id: ObjectId("6005c050d36d9acd28b8679b")}, null, null)`

---

<div class="post-metadata">

**Author:** ![conker84](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/conker84/32/275_2.png) [@conker84](https://community.neo4j.com/u/conker84)\
**Post date:** [January 25, 2021, 9:50am UTC](https://community.neo4j.com/t/any-way-to-query-apoc-mongodb-find-by-objectid/32523/2 "2021-01-25T09:50:28Z")

</div>

@enstricht thank you for reaching us now is not possible get the document by Object id value, I opened an issue in order to add a new feature ASAP:

> <https://github.com/neo4j-contrib/neo4j-apoc-procedures/issues/1784>
>
> Add a procedure \`apoc.mongo.get.byObjectId(\<hostOrKey\>, \<db\>, \<collection\>, \<obj…ectIdValueAsString\>, \<fieldName, default=\_id\>)\` in order to get the the documents by ObjectId becayse now not it's not possibile.

Thank you so much for pointing this out!

---

<div class="post-metadata">

**Author:** ![giuseppe\_villan](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/giuseppe_villan/32/11871_2.png) [@giuseppe\_villan](https://community.neo4j.com/u/giuseppe_villan)\
**Post date:** [January 25, 2021, 7:15pm UTC](https://community.neo4j.com/t/any-way-to-query-apoc-mongodb-find-by-objectid/32523/3 "2021-01-25T19:15:45Z")

</div>

@enstricht I created the new procedure, awaiting approval, `apoc.mongodb.get.byObjectId(<host>,<db>,<collection>,<objectIdAsString>, <fieldValue: default='_id'>, <optionalConfigMap>)`.  
For example, to get a document with object id, you can type `CALL apoc.mongodb.find("mongodb://host:port", "testdb", "testcoll", "6005c050d36d9acd28b8679b")`.  
In optionalConfigMap you can put `compatibleValues` (to convert MongoDB data types into Neo4j data types, with default `true`), `extractReferences` (it will include the related document instead of the ObjectId, default: `false`).

Unfortunately I cannot attach the .jar with this new procedure, because it is not a supported format.
