I'm pulling my hair out.
I've tried using mongoose:
const ObjectId = require('mongoose').Types.ObjectId;
let id = new ObjectId(peson["_id"]);
When I console.log(id) it just shows the string value. When I append the id into an array in another object I'm using, and I JSON.stringify() that whole object I get just the '1djd892jowidj3wfejk93' string values.
When I pass my searchObject to Mongo, it doesn't return results.
I've also tried using the native MongoDB driver for node:
const {ObjectId} = require('mongodb');
let id = Objectid("1djd892jowidj3wfejk93")
this also returns just a string value when when logging to the console and also embedding in parent search request. JSON.stringify() shows just the string, and the query returns empty.
the native NodeJs mongoDb driver
const devices = await Device.find({ owner: req.user._id });
. I think mongoDB handles any conversion to an ObjectId – dikuw