[SERVER-14952] count and find inconsistent when using $not and a regex Created: 19/Aug/14  Updated: 03/Sep/14  Resolved: 03/Sep/14

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 2.4.3, 2.4.10
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Roelof Spijker Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File test.json    
Issue Links:
Duplicate
duplicates SERVER-9812 User query is interpreted incorrectly... Closed
Operating System: ALL
Participants:

 Description   

I have a simple collection containing documents with 2 fields each:

_id (ObjectId),
query (String)

There is a single default index on the collection on the _id field.

Now, when I perform a query like:

db.collection.find({"query":/value/})

I get results, as expected.

However, when I perform a query like:

db.collection.find({"query":{$not:/iid/}})

I get no results. Even though

db.collection.count({"query":{$not:/iid/}})

returns 11000.

If I perform a .explain() on the find query, it tells me that it scanned all ~40K objects in the collection and that n is in fact 11000. A db.collection.find(...).count() gives me 11000 as well. A db.collection.find(...).hasNext() gives me false though.

I've tried this on two separate systems (2.4.10 and 2.4.3) with the exact same result. I've tried $not:

{/regex/}

on other databases in the same system and it works fine. So it seems to be related to the data in this specific collection.

Some example documents (without _id):

{"query":"iid: \"53dabd72a38933046cbe7290\""},
{"query":"cbunid: { $ne: null, $in: [ null, null, null, null, null, null, null, null, null, null, null, null, null, null, null ] }" },
{"query":"_t: \"Collection\", iid: \"534e7d47749cd80b202a8f19\""},
{"query":"iid: { $in: [ \"536178f2749cd80b2082b394\" ] }" }

So, here I would expect the query to match the 3rd document. In fact, importing this small test and running the query displays the problem. I've attached a .json file which can be imported with mongoimport --jsonArray.

The documents were imported using mongoimport from a file containing a jsonArray with the exact amount of documents as were imported into the DB.



 Comments   
Comment by Ramon Fernandez Marina [ 03/Sep/14 ]

rspijker, thanks for your report, this is a duplicate of an existing ticket: SERVER-9812. You can rename the "query" field in your collection, or wrap your queries around a $query operator as described here.

As for JSON formatting, JIRA wants things wrapped in {code}...{code} directives to do a nice formatting.

Regards,
Ramón.

Comment by Roelof Spijker [ 19/Aug/14 ]

I'm not sure why JIRA messed up the formatting on the JSON. I assure you, it's properly formatted in my files/shell.

Generated at Thu Feb 08 03:36:27 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.