I'm facing an issue when trying to run a specific query.
db.getCollection('name').find({_id : ObjectId("hereGoesAnId")})
My setup involves using the mongodb module and utilizing cy.task to execute queries on the database. Everything works fine, as long as I'm querying based on attributes other than _id.
The problem arises when I need to identify the task by its id, which requires using ObjectId. However, this is causing issues for me.
If I attempt to send the query in this manner:
const result = await.collection.find({_id: `ObjectId(${varName})`}).toArray()
The result ends up empty because ObjectId is interpreted as a string and no matching records are found.
On the other hand, if I try it like this:
const result = await.collection.find({_id: ObjectId(`${varName}`)}).toArray()
I encounter an error stating "ObjectId is not defined..."
Since I'm still new to mongo, I'm unsure if there's a workaround for this situation?