I ran a find with:
find({ field1: { $gte: xxx, $lte: yyy }, field3: { $ne: null },
field2: "xxx"}, field4: /regex/).explain()
and I got:
{ "cursor" : "BtreeCursor field1_1", "nscanned" :
3701529, "nscannedObjects" : 3701529, "n" : 10043,
"millis" : 2563332, "nYields" : 48555, "nChunkSkips" :
0, "isMultiKey" : false, "indexOnly" : false,
"indexBounds" : { "field1" : [ [
xxx, yyy
] ] }}
Looks like it only used the index on field1, not the one on field2.
My question is: can Mongo merge the inverted lists of 2 indexes to
make the query faster or do I need to create compound index ?
If I create a compound index on field1 + field2, would it work in that case ?
Thanks,
--
Philippe
Allgoob SA
--
Philippe
Allgoob SA
--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
Another question, does $ne make use of an index.
For instance I have field3: { $ne: null }, in my query.
--
Philippe
Allgoob SA
Philippe DAVID wrote:
> Ok, thank you for the answer.
>
> Another question, does $ne make use of an index. For instance I have
> field3: { $ne: null }, in my query.
a NOT operation usually does not work with indexes for most
databases.
- -aj
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iQGUBAEBAgAGBQJPITYxAAoJEADcfz7u4AZjrDYLv2/UnKLIcIcZvr5kKVXHWqSw
VrkGVW7Jpue7G6lRhQgoDCEoSR1MQwojJMYRjjmx1nt406/Z56O+PGgJlTIBjPS4
hvusJ1eYgvvLxllSM84GSWjbPRUVc+pvi0LUxSXujDAyt8y33icN+Vn+1tRYom6O
fy4s+x7jebdf+dRojlYRO1ClOQFw07660bdkADY+0TNs9cQ+WjGCexWjJ67h4qKG
v3z6XHcCf972QtyYOoyjDOKyOA6R1FsR0GAjEwrfILtWEayOwRwqnigNQeI8UhTB
kc5/bm4ZUuD8HWlQIcGz3/N66c7coC2X+Il4NvSs2F5PN9RI8yVApxKv1RAbYQ8/
jyEacosncH0bxA9M4Z5GFwTI9kOXdunQbufIMsB0MCzy4F9hR+QS8TZfOFxqMKET
8qPCYKjZeohFz7f8u7pwOyJsw9hJ0yQkbYM+yuFEaIPcfEIsjUNbYONiUDkefOSS
fNtkKxhK60JDHrvjvOVzn5+XuDqKQNk=
=z7yD
-----END PGP SIGNATURE-----
MongoDB can use indexes for $ne and $nin queries. But if most of the values are not null it won't be selective and thus won't be very helpful unless its part of a compound index.
Also note that index behavior for missing/null values is different with sparse indexes.
-- Max
Not equal queries are hard to evaluate off of search engine style inverted indexes but not particularly hard off btree type indexes. Without knowing the mind of other database developers, it may have been left out because it was deemed not useful. Personally I have found application developers to make great creative use of database features :)
-- Max