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

DNAScanner
  • 74
  • 7

1 Answers1

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

Black Mamba
  • 13,632
  • 6
  • 82
  • 105
  • I tried it but it didnt return me anything, neither after the curl or in the node-console, tried [this](https://pastebin.com/rpKSX188). Console logging the `inSession` directly, outputs `"null"` – DNAScanner May 04 '22 at 14:47
  • Sorry, didnt look in here for a few days, thank you, that works actually – DNAScanner May 15 '22 at 07:18