0

I'm trying to find the user with the incoming request.

router.get("/user", auth, (req, res) => {
    const db = mongoUtil.getDb();
    db.db("mern-auth-2").collection("users").findOne({_id: ObjectId(`${req.user.id}`)})
    .select('-password')
    // console.log(req.user.id)
    .then(user => res.json(user));
});

The req.user.id is console logging abcdefg for example and in my database it's ObjectId('abcdefg')

How do I compare these 2? Above is currently what I have coded, which doesn't work.

Elizabeth
  • 157
  • 1
  • 15
  • Does this answer your question? [How to convert a string to ObjectId in nodejs mongodb native driver?](https://stackoverflow.com/questions/21076460/how-to-convert-a-string-to-objectid-in-nodejs-mongodb-native-driver) – Gibbs Jan 19 '21 at 04:53
  • No, I need to extract the value from ObjectId so I can compare it to my incoming request, which just case the number – Elizabeth Jan 19 '21 at 05:56

0 Answers0