How use ObjectId search from Webhook in MongoDB

After Running this :

mcollection.find({“id”:“1”}).toArray();

Output :

[
  {
    "_id": {
      "$oid": "606aa80e929a618584d2758b"
    },
    "id": "1",
    "tid": "1",
    "cid": "1",
    "title": "What is Time Complexity",
    "description": "So, the time complexity is the number of operations an algorithm performs to complete its task (considering that each operation takes the same amount of time).",
    "image": "https://i.pinimg.com/originals/af/e4/0b/afe40bd0ee0a6b0e34daacd74078391e.jpg",
    "author": "Hanry Kon"
  }
]

I want same output based on ObjectId as Input
like :

mcollection.find({“_id”:ObjectId(“606aa80e929a618584d2758b”)}).toArray();

Error after Running this Code:

> error: 
ReferenceError: 'ObjectId' is not defined
> trace: 
ReferenceError: 'ObjectId' is not defined
	at exports (function.js:28:43(28))
	at function_wrapper.js:3:34(21)
	at <eval>:11:8(17)
	at <eval>:2:15(7)

How can i do that By Using MongoDB Webhook

Did you import?

import { ObjectId } from "bson"
1 Like

Thanks for Reply I was Able to solve my problem through this Article.

Solution : mcollection.find({"_id":new BSON.ObjectId(“606aa80e929a618584d2758b”)}).toArray();

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.