Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Message: bad query: BadValue: unknown top level operator: $ne #208

Open
ravinegi17 opened this issue Aug 24, 2021 · 1 comment
Open

Message: bad query: BadValue: unknown top level operator: $ne #208

ravinegi17 opened this issue Aug 24, 2021 · 1 comment

Comments

@ravinegi17
Copy link

I need help it's very urgent actually I am using MongoDB as a DB and there is a query required where I need to put condition $ne, but it is showing the error consistently (Message: bad query: BadValue: unknown top-level operator: $ne
)
My sample code for idea:
$whereCondition = array(array('status'=>'A'));
$whereCondition2 = array(array('property_verified','P'));

array('$match'=>array('$and'=>$whereCondition,'$ne'=>$whereCondition2)),

till $and condition its working properly but when adding $ne condition its is throwing same above mentioned error.
My mongo shell version is: 3.2.22

Thanks in advance
Please help

@mjrb
Copy link
Contributor

mjrb commented Sep 4, 2021

Is this php code? I'm not sure what this has to do with monger, the community clojure driver. In the future please consult the mongodb manual for questions not specific to monger. Here is the manual page for $ne https://docs.mongodb.com/manual/reference/operator/query/ne/

Sorry I might be a little confused by the question but I will try to help.

A more standard way of writing what I think your query is in the mongodb shell (js) would be db.yourCollection.aggregate({$match: {$and: [{status: "A"}, {$ne: {propertyVerified: "P"}}]}}) this query is very confusing in a mongodb context but seems to be a loose translation of the sql expression where status='A' and propertyVerified!='P'. MQL isn't 1:1 translatable to sql this way. The query you may be looking for is {$match: {status: "A", propertyVerified: {$ne: "P}} in MQL the ands are implied and the values of the map/dict/hashMap are the values the field are the expression that field should match.

Because you have something like {$ne: {propertyVerified: "P"}} and mongo is trying to tell you you shouldn't put $ne there and should probably have something like {propertyVerified: {$ne: "P"}}

Does this help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants