0

How do you do a negative regex query in Mongodb?

I want to find all documents, where "Name" does not contain the string "james". E.g. filter out "james" or "john james" or "john james peter" or "somethingjames"

This works, but ONLY if the string begins with "james".

db.name.find({"name":/^((?!james).)/i});

What's wrong?

Community
  • 1
  • 1
Nima
  • 937
  • 1
  • 13
  • 20

0 Answers0