mongodb-indexes

MongoDB regular expression with indexed field

两盒软妹~` 提交于 2019-12-01 02:12:40
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 i'm launching the same query, but with no index in collection, the performance is much better. > db

MongoDB - Unique index vs compound index

 ̄綄美尐妖づ 提交于 2019-11-30 20:22:29
Assume a hypothetical document with 3 fields: _id : ObjectId emailAddress : string account : string Now, given a query on emailAddress AND account, which of the following two indexes will perform better: Unique index on emailAddress alone (assume it is a unique field) Compound index on account and emailAddress In terms of performance the difference will be small at best. Due to the fact that your e-mail addresses are unique any compound index that has an e-mail field will not ever be more helpful than an index on e-mail address alone. The reason for this is that your e-mail field already has

MongoDB - Unique index vs compound index

百般思念 提交于 2019-11-30 04:10:16
问题 Assume a hypothetical document with 3 fields: _id : ObjectId emailAddress : string account : string Now, given a query on emailAddress AND account, which of the following two indexes will perform better: Unique index on emailAddress alone (assume it is a unique field) Compound index on account and emailAddress 回答1: In terms of performance the difference will be small at best. Due to the fact that your e-mail addresses are unique any compound index that has an e-mail field will not ever be

Partial indexes in mongodb / mongoose

橙三吉。 提交于 2019-11-29 13:52:32
In the sparse index documentation I found note about mongodb 3.2 partial indexes Changed in version 3.2: Starting in MongoDB 3.2, MongoDB provides the option to create partial indexes. Partial indexes offer a superset of the functionality of sparse indexes. If you are using MongoDB 3.2 or later, partial indexes should be preferred over sparse indexes. Partial indexes are very helpfull and I want to use them in my project. Is it possible use them with mongoose? Angelos Veglektsis In the current Mongoose version 4.3.7 you cannot define partial indexes in the scheme, but you can still use Partial

Mongo unique index case insensitive

*爱你&永不变心* 提交于 2019-11-29 11:37:31
@CompoundIndexes({ @CompoundIndex(name = "fertilizer_idx", unique = true, def = "{'name': 1, 'formula': 1, 'type': 1}") }) public class Fertilizer extends Element implements Serializable { //class stuff } Is it possible to create the index case insensitive? Right now it is differentiating from NAME to NAMe . Saving a second field lowercase (or uppercase) is not a possibility for me. Thanks, Pedro Prior of MongoDB version 3.4 we were unable to create index with case insensitive . In version 3.4 has collation option that allows users to specify language-specific rules for string comparison ,

MongoDB - too much data for sort() with no index error

好久不见. 提交于 2019-11-29 05:51:36
问题 I am using MongoDB 1.6.3, to store a big collection (300k+ records). I added a composite index. db['collection_name'].getIndexes() [ { "name" : "_id_", "ns" : "db_name.event_logs", "key" : { "_id" : 1 } }, { "key" : { "updated_at.t" : -1, "community_id" : 1 }, "ns" : "db_name.event_logs", "background" : true, "name" : "updated_at.t_-1_community_id_1" } ] However, when I try to run this code: db['collection_name'] .find({:community_id => 1}) .sort(['updated_at.t', -1]) .skip(@skip) .limit(

Change type of field inside mongoDB aggregation and does $lookup utilises index on fields or not?

荒凉一梦 提交于 2019-11-28 11:50:47
I am performing joins in mongodb using $lookup, now i am facing a problem here. I have two collections first one to contains users all bookmarks brands and the second one contains all details about the brands.Now i am trying to return all brands details bookmarked by the user. user_bookmarked Collection {"mobile_no": "8971740148", "brands": ["5829c1df334d40e20e1d1c19", "5829c1df334d40e20e1d1c20", "5829c1df334d40e20e1d1c21"]} brands Collection {"_id": ObjectId("5829c1df334d40e20e1d1c19"), "brand_name": "Versace"} {"_id": ObjectId("5829c1df334d40e20e1d1c20"), "brand_name": "Lee Cooper"} {"_id":

Partial indexes in mongodb / mongoose

本小妞迷上赌 提交于 2019-11-28 07:57:03
问题 In the sparse index documentation I found note about mongodb 3.2 partial indexes Changed in version 3.2: Starting in MongoDB 3.2, MongoDB provides the option to create partial indexes. Partial indexes offer a superset of the functionality of sparse indexes. If you are using MongoDB 3.2 or later, partial indexes should be preferred over sparse indexes. Partial indexes are very helpfull and I want to use them in my project. Is it possible use them with mongoose? 回答1: In the current Mongoose

Mongo unique index case insensitive

自闭症网瘾萝莉.ら 提交于 2019-11-28 04:57:19
问题 @CompoundIndexes({ @CompoundIndex(name = "fertilizer_idx", unique = true, def = "{'name': 1, 'formula': 1, 'type': 1}") }) public class Fertilizer extends Element implements Serializable { //class stuff } Is it possible to create the index case insensitive? Right now it is differentiating from NAME to NAMe . Saving a second field lowercase (or uppercase) is not a possibility for me. Thanks, Pedro 回答1: Prior of MongoDB version 3.4 we were unable to create index with case insensitive . In

Change type of field inside mongoDB aggregation and does $lookup utilises index on fields or not?

穿精又带淫゛_ 提交于 2019-11-27 06:32:08
问题 I am performing joins in mongodb using $lookup, now i am facing a problem here. I have two collections first one to contains users all bookmarks brands and the second one contains all details about the brands.Now i am trying to return all brands details bookmarked by the user. user_bookmarked Collection {"mobile_no": "8971740148", "brands": ["5829c1df334d40e20e1d1c19", "5829c1df334d40e20e1d1c20", "5829c1df334d40e20e1d1c21"]} brands Collection {"_id": ObjectId("5829c1df334d40e20e1d1c19"),