--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/d46893c7-8796-461c-acad-9b94987d8836%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
Hi Jeremy
Do you know if these behaviors are documented anywhere? It seems like a bug to me that mongo needs to fetch all of the documents to count with the “$eq: null” and “$ne: null” queries.
Part of the reason is because they’re different queries, and null
values are treated differently from exact values:
> db.test.find()
{ "_id": ObjectId("586b3557af05082123fcb2f8"), "a": 1 }
{ "_id": ObjectId("586b3559af05082123fcb2f9"), "b": 1 }
{ "_id": ObjectId("586b360daf05082123fcb2fa"), "a": null, "c": 1 }
> db.test.find({a:null})
{ "_id": ObjectId("586b3559af05082123fcb2f9"), "b": 1 }
{ "_id": ObjectId("586b360daf05082123fcb2fa"), "a": null, "c": 1 }
> db.test.find({a:{$ne:null}})
{ "_id": ObjectId("586b3557af05082123fcb2f8"), "a": 1 }
{a:null}
will match documents where {a:null}
and also documents where a
doesn’t exist, while {a:{$ne:null}}
will match documents where field a
exists and its value is not null
. For more information, please see: https://docs.mongodb.com/v3.2/tutorial/query-for-null-fields/
Best regards,
Kevin
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/b49be86a-d3d8-4264-9a64-df07c86c84cb%40googlegroups.com.
You received this message because you are subscribed to a topic in the Google Groups "mongodb-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mongodb-user/O-fMpLuzulY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mongodb-user+unsubscribe@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/CABk9snqJ6MtEoiWvGURGgWvnFLn43PCBYtF8R5zhJ8iVzgORxw%40mail.gmail.com.
Hi Jeremy,
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to a topic in the Google Groups "mongodb-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mongodb-user/O-fMpLuzulY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mongodb-user+unsubscribe@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/8cd207fb-a672-4965-aa1c-e3c9effa15a0%40googlegroups.com.
Therefore, documents need to be fetched.
I do have two counter arguments.
i). If we agree with this argument, Why should IXSCAN required at all ? It can be only document scan.
ii) considering same argument, for query {a:123} also should fetch documents.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
I did indeed find that queries like this:db.test.find({a:{$gt:0}}).count()will use COUNT_SCAN and they will match only documents where a both exists and is an integer greater than 0.This was useful for some (but not all) of my use cases. In general if you have a lower bound (or just use the data type's min and $gte) and the field only has a single data type, this can work. I haven't tested it for all data types though.I tried to be clever and use constructs such as {$not: {$lt: 0}} to match multiple data types (because I think mismatched data types always return FALSE no matter what the comparison operation is). Unfortunately those types of queries did not show COUNT_SCAN in the output of explain().Jeremy
On Fri, Jun 2, 2017 at 11:28 AM, Astro <andhar...@gmail.com> wrote:
Hi Jeremy,Did you guys able to optimize such kind of calls which includes a match with null?Any help will be appreciated.
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to a topic in the Google Groups "mongodb-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mongodb-user/O-fMpLuzulY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
Hi Monika
.find({a:{$ne:v}}.count() use IXSCAN + count stage, but docexamined are 0.
.find({a:{$ne:null}}.count() use IXSCAN + count stage, but docexamined are same as key examined.
Generally, having zero docs examined
means that the query can be answered by using the index. This is as opposed to having a non-zero docs examined
value, which means that the query cannot answer the query without loading the document into memory, and verify that the document satisfies the conditions of the query.
Having a zero docs examined
is the goal of having a covered query, means that the query can be answered using only the index. This can typically be achieved by using a well-defined boundaries on the query, along with the use of projections to ensure that the output fields are aligned with the index.
In terms of your two examples, the first example shows a defined boundaries: documents having field a
not equal to some value.
In contrast, the second example is less defined: documents having field a
containing null
, or documents with no field a
at all. Since in MongoDB both cases are recorded the same way in the index, MongoDB must reconfirm the exact situation by inspecting the document.
I believe the relevant ticket for you would be SERVER-12869 which is the ticket that suggests to index null values and missing values differently. Please watch/upvote/comment on the ticket if you find it relevant.
Best regards
Kevin