0

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

1

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

2 Comments

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"
Sorry, didnt look in here for a few days, thank you, that works actually

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.