Info
Hello MongoDB Community
I am having trouble with $not operator. Getting error that "$not cannot have a regex". I looked into official documentation but it's says it shall work from version 4.0.7. So, I tried updating my mongodb and installed latest stable version 4.0.10. But still getting same error. I am attaching my error screenshot. Please let me know if I am doing anything wrong.
Many thanks in advance.
Top User Comments
yeshu@outlook.in commented on Wed, 17 Jul 2019 04:28:28 +0000:
Hi Kelsey,
Thank you for replying. Please accept my apologies, because I did update the mongoDb version, but somehow brew service not updated with new version. Once I looked at by ```db.version()``` I found the issue. So, I restart the service with newer version and query is running without any error.
Thank you so much for your time.
thomas.schubert commented on Tue, 16 Jul 2019 18:39:37 +0000:
Hi yeshu@outlook.in,
Would you please confirm the version of the mongod that is running by executing db.version() from the shell? I'm not able to reproduce this issue:
> db.categories.find({name: {'$not':{'$regex': /e/ }}})
Error: error: {
"ok" : 0,
"errmsg" : "$not cannot have a regex",
"code" : 2,
"codeName" : "BadValue"
}
> db.version()
4.0.6
> db.categories.find({name: {'$not':{'$regex': /e/ }}})
> db.version()
4.0.10
Thanks,
Kelsey