mongodb-indexes

Mongo Triple Compound Index

孤街浪徒 提交于 2019-12-18 05:17:23
问题 If you have a double compound index { a : 1, b : 1}, it makes sense to me that the index won't be used if you query on b alone (i.e. you cannot "skip" a in your query). The index will however be used if you query on a alone. However, given a triple compound index { a : 1, b: 1, c: 1} my explain command is showing that the index is used when you query on a and c (i.e. you can "skip" b in your query). How can Mongo use an abc index on a query for ac , and how effective is the index in this case

A list of indices in MongoDB?

廉价感情. 提交于 2019-12-17 17:41:32
问题 Is there a way to see a list of indices on a collection in mongodb in shell? i read through http://www.mongodb.org/display/DOCS/Indexes but i dont see anything 回答1: From the shell: db.test.getIndexes() For shell help you should try: help; db.help(); db.test.help(); 回答2: And if you want to get list of all indexes in your database: use "yourdbname" db.system.indexes.find() 回答3: If you want to list all indexes: db.getCollectionNames().forEach(function(collection) { indexes = db[collection]

A list of indices in MongoDB?

╄→尐↘猪︶ㄣ 提交于 2019-12-17 17:41:16
问题 Is there a way to see a list of indices on a collection in mongodb in shell? i read through http://www.mongodb.org/display/DOCS/Indexes but i dont see anything 回答1: From the shell: db.test.getIndexes() For shell help you should try: help; db.help(); db.test.help(); 回答2: And if you want to get list of all indexes in your database: use "yourdbname" db.system.indexes.find() 回答3: If you want to list all indexes: db.getCollectionNames().forEach(function(collection) { indexes = db[collection]

sparse indexes and null values in mongo

落花浮王杯 提交于 2019-12-17 16:16:12
问题 I'm not sure I understand sparse indexes correctly. I have a sparse unique index on fbId { "ns" : "mydb.users", "key" : { "fbId" : 1 }, "name" : "fbId_1", "unique" : true, "sparse" : true, "background" : false, "v" : 0 } And I was expecting that would allow me to insert records with null as the fbId, but that throws a duplicate key exception. It only allows me to insert if the fbId property is removed completely. Isn't a sparse index supposed to deal with that? 回答1: Sparse indexes do not

Overflow sort stage buffered data usage exceeds internal limit

给你一囗甜甜゛ 提交于 2019-12-17 02:34:32
问题 Using the code: all_reviews = db_handle.find().sort('reviewDate', pymongo.ASCENDING) print all_reviews.count() print all_reviews[0] print all_reviews[2000000] The count prints 2043484 , and it prints all_reviews[0] . However when printing all_reviews[2000000] , I get the error: pymongo.errors.OperationFailure: database error: Runner error: Overflow sort stage buffered data usage of 33554495 bytes exceeds internal limit of 33554432 bytes How do I handle this? 回答1: You're running into the 32MB

How can I use partialFilterExpression on a mongoose model

半世苍凉 提交于 2019-12-13 03:23:04
问题 I have created a mongoose model that has an email field. I want it to be unique if a value is provided by a user but I want it to be empty is a user has not provided any value. I have found a good mongodb reference here: https://docs.mongodb.com/manual/core/index-partial/#partial-index-with-unique-constraints that could work but I don't know how to make it work on mongoose This is how the field looks like right now email: { type: String, index: true, unique: true } If I leave it the way it is

Mongodb query - Does sequence of key matters in usage of compound index

亡梦爱人 提交于 2019-12-13 02:57:26
问题 Suppse I created index like following :- db.collection.createIndex( { propA: 1, propB: 1, propC:1 } ) and I query like following :- db.collection.find({propB:'x', propC: 'y', propA:'z'}) will mongo query engine use the index created above or not. Does sequence of key matters in usage of compound index while writing query? 回答1: The order of keys in a query doesn't matter: MongoDB is smart enough to look at all the queried properties and find a suitable index. However, the order of keys defined

MongoDB: How to index unknown fields

放肆的年华 提交于 2019-12-11 15:49:16
问题 We're storing documents with a undefined structure. I mean, it has a basic structure ( id , user and creationTimestamp ), but is also there a Map<String, Object> values fields, where we are able to store whichever structure: public class Metadata { private String id; private String user; private Date creationTimestamp; private Map<String, Object> values; } Example: > db.metadata.find(); { "_id" : "Doc2Ref2Mdt1", "user" : "user1", "creationTimestamp" : ISODate("2018-09-24T12:20:56.958Z"),

MongoDB: why doesn't sorting by multiple keys use an index?

匆匆过客 提交于 2019-12-10 17:46:30
问题 Question: I have a very large collection that is indexed by field ts : (timestamp) > db.events.ensureIndex({'ts': -1}) I want to get last 5 entries. What surprises me is that the query doesn't use the index and is thus very slow: > db.events.find().sort({'ts': -1, '_id': -1}).limit(5) However, sorting just by ts or the other field uses index as it should: > db.events.find().sort({'ts': -1}).limit(5) > db.events.find().sort({'_id': -1}).limit(5) Is this a bug in MongoDB, is this indeed a

MongoDB 2dsphere index fails (malformed geometry?)

前提是你 提交于 2019-12-10 13:28:26
问题 I'm currently trying to build an 2dsphere index, but the creation seems to fail. The document on which the index creation fails is valid geojson (according to geojsonlint). Also as far as I can see it obeys the MongoDB "Polygon" rules. I would appreciate any help, since I can't figure out why the index creation seems to fail. Thanks in advance! db.poly.ensureIndex( { loc: "2dsphere" } ) { "createdCollectionAutomatically" : false, "numIndexesBefore" : 1, "ok" : 0, "errmsg" : "Can't extract geo