mongodb-indexes

Why Mongo query for null filters in FETCH after performing IXSCAN

南楼画角 提交于 2020-01-15 11:52:59
问题 According to Mongo Documentation, The { item : null } query matches documents that either contain the item field whose value is null or that do not contain the item field. I can't find documentation for this, but as far as I can tell, both cases (value is null or field is missing) are stored in the index as null . So if I do db.orders.createIndex({item: 1}) and then db.orders.find({item: null}) , I would expect an IXSCAN to find all documents that either contain the item field whose value is

Advantage of a unique index in MongoDB

∥☆過路亽.° 提交于 2020-01-11 04:33:05
问题 I've tried to search through Mongo documentation, but can't really find any details on whether queries on unique indexes will be faster than queries on non-unique indexes (given the same data) So I understand that a unique index will have high selectivity and good performance. But, given two fields whose concatenation is unique, would a non-unique compound index perform slower than a unique compound index? I am assuming that unique indexes can slow down inserts as the uniqueness must be

Which of the following queries will use the index?

风流意气都作罢 提交于 2020-01-05 04:19:07
问题 Given collection foo with the following index: db.foo.createIndex( { a : 1, b : 1, c : 1 } ) We need to select which of the following queries will use the index? db.foo.find( { c : 1 } ).sort( { a : -1, b : 1 } ) db.foo.find( { b : 3, c : 4 } ) db.foo.find( { a : 3 } ) db.foo.find( { c : 1 } ).sort( { a : 1, b : 1 } ) I'm surprised that 3 , 4 are correct options and 1 , 2 are not. Why is the following queries will use the index? db.foo.find( { a : 3 } ) This seems to be able to use the index

Why MongoDB doesn't use Index Intersection?

牧云@^-^@ 提交于 2020-01-03 07:29:18
问题 I am trying to reproduce the first example of index intersection instruction (http://docs.mongodb.org/manual/core/index-intersection/) but facing a problem: mongo doesn't uses both indexes My steps: Download mongo (3.0.3) and install it Run mongod: mongod.exe --dbpath d:\data (folder is empty) Run mongo: mongo.exe Add indexes: db.orders.ensureIndex({ qty: 1 }) db.orders.ensureIndex({ item: 1 }) db.orders.getIndexes() [{ "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "test.orders" },

Why MongoDB cannot use a compound index that is much similar(not exact) to the query?

大城市里の小女人 提交于 2020-01-01 03:53:10
问题 Consider the below Mongo index strategy and the query, Index: db.collec.ensureIndex({a:1,b:1,c:1}); Query: db.collec.find({"a":"valueA"},{"_id":0,"a":1,"c":1}).sort({"c":-1}).limit(150) The explain on the above query returns: /* 0 */ { "cursor" : "BtreeCursor a_1_b_1_c_1", "isMultiKey" : false, "n" : 150, "nscannedObjects" : 178, "nscanned" : 178, "nscannedObjectsAllPlans" : 279, "nscannedAllPlans" : 279, "scanAndOrder" : true, "indexOnly" : true, "nYields" : 0, "nChunkSkips" : 0, "millis" :

Mongo indexing on object arrays vs objects

余生颓废 提交于 2019-12-31 08:12:51
问题 I'm implementing a contact database that handles quite a few fields. Most of them are predefined and can be considered bound, but there are a couple that aren't. We'll call one of these fields 'groups'. The way we currently implement it is (each document/contact has 'groups' field): 'groups' : { 152 : 'hi', 111 : 'group2' } but after some reading I've it would seem I should be doing it: 'groups' : [ { 'id' : 152, 'name' : 'hi' }, { 'id' : 111, 'name' : 'group2' } ... ] and then apply the

Mongo indexing on object arrays vs objects

断了今生、忘了曾经 提交于 2019-12-31 08:12:07
问题 I'm implementing a contact database that handles quite a few fields. Most of them are predefined and can be considered bound, but there are a couple that aren't. We'll call one of these fields 'groups'. The way we currently implement it is (each document/contact has 'groups' field): 'groups' : { 152 : 'hi', 111 : 'group2' } but after some reading I've it would seem I should be doing it: 'groups' : [ { 'id' : 152, 'name' : 'hi' }, { 'id' : 111, 'name' : 'group2' } ... ] and then apply the

MongoDB regular expression with indexed field

笑着哭i 提交于 2019-12-30 07:52:14
问题 I was creating my first app using MongoDB. Created index for a field, and tried a find query with $regex param, launched in a shell > db.foo.find({A:{$regex:'BLABLA!25500[0-9]'}}).explain() { "cursor" : "BtreeCursor A_1 multi", "nscanned" : 500001, "nscannedObjects" : 10, "n" : 10, "millis" : 956, "nYields" : 0, "nChunkSkips" : 0, "isMultiKey" : false, "indexOnly" : false, "indexBounds" : { "A" : [ [ "", { } ], [ /BLABLA!25500[0-9]/, /BLABLA!25500[0-9]/ ] ] } } It's very strange, because when

mongodb compund index vs. index intersect

我们两清 提交于 2019-12-25 06:12:27
问题 There will be about 3 billion docs in the collection across shards. Assuming I would be using queries that is not fulfilled entirely by the index(es). And I am not using the keys for sorting. Does it make sense to have indexes as follows (which match the queries): {"sid":1, "cid":1, "mid":1} {"cid":1, "hid":1, "mid":1} {"mid":1, "hid":1, "sid":1} {"hid":1, "sid":1, "cid":1, "mid":1} {"mid":1, "cid":1} {"mid":1, "sid":1} Or: {sid:1} {cid:1} {hid:1} {mid:1} 回答1: This is a valid question. You

How to use full text search for unknown number of children of a field in Mongodb?

前提是你 提交于 2019-12-23 05:42:19
问题 I have a document with one field description like this: { "_id": "item0", "description": { "parlist": [ { "listitem": { "text": { "child": "page rous lady", "keyword": "officer e" } } }, { "listitem": { "text": "shepherd noble " } } ] } } How to create text index on description and search for specific word? I don't know how depth can description go and how many children will description have. I tried with index creation like this: db.collection.ensureIndex({description:"text"}) and then for