0

How to use nin and regex in mongoDB?

I want to find document using nin and regex

but nin does not work!

Query:

{ "$and" : [ 

{ "id" : { "$nin" : [ "529653cb5bc5b0e42d339bd3" , "529653cb5bc5b0e498339bd3"]}} ,

{ "content" : { "$regex" : "(?i)apple" , "$options" : "i"} }

] }

Should I using mongo subquery?

HamZa
  • 14,671
  • 11
  • 54
  • 75

1 Answers1

0

Your problem could be multiple things depending upon the error you're getting.

But a quick examination of your query suggests it could be your use of the "id" field. The primary key field in all documents is "_id". Your query uses the field "id" but you're probably trying to query the field "_id".

Adam Harrison
  • 3,323
  • 2
  • 17
  • 25