in NodeJS with Mongoose, how do i search something in an array using findOne()? I want to search stuff like 626ead978edc5f2a3f7ca924 in the users array in my sessionCollection-Model.
My DB looks like this: Database Picture
-
Did you check this? mongodb.com/docs/manual/reference/operator/query/inJimmy– Jimmy2022-05-04 18:10:31 +00:00Commented May 4, 2022 at 18:10
Add a comment
|
1 Answer
It'll work normally as it does for non array key:
SessionCollection.findOne({users: mongoose.Types.ObjectId("626ead978edc5f2a3f7ca924")})
You might need to cast to objectId to get the desired result. Reference
2 Comments
DNAScanner
I tried it but it didnt return me anything, neither after the curl or in the node-console, tried this. Console logging the
inSession directly, outputs "null"DNAScanner
Sorry, didnt look in here for a few days, thank you, that works actually