I am trying to query against the following mLab Database document in my React component:
{
"_id": {
"$oid": "5e7a4fece9cee40348a63dff"
},
"userId": "5e7a4fc6e9cee40348a63dfe",
"timestamp": {
"$date": "2020-03-24T18:10:43.955Z"
},
"isDeleted": false,
"__v": 0
}
Below is what I'd like to do but I can't seem to get access the $oid
value with my query. I have tried wrapping the token value in mongoose.Types.ObjectId(token)
as well as the answer here. But if I use $oid
I get an error saying it cannot be used.
const token = req.body.token;
UserSession.find(
{
_id: token, // Get an error here
isDeleted: false
},
(err, sessions) => {
if (err) {
return res.send({
success: false,
message: "Server Error..." + err
});
if (sessions.length != -1) {
return res.send({
success: true,
message: "Good"
});
}
}
}
);
I am totally out of ideas and couldn't find anything that works here on SO or in mLab/MongoDB docs. Any help much appreciated.