mongodb-indexes

MongoException: Index with name: code already exists with different options

风流意气都作罢 提交于 2019-12-08 16:13:28
问题 I have a mongodb collection term with following structure { "_id" : "00002c34-a4ca-42ee-b242-e9bab8e3a01f", "terminologyClass" : "USER", "code" : "X67", "terminology" : "some term related notes", "notes" : "some notes" } and a java class representing the term collection as Term.java @Document public class Term{ @Id protected String termId; @Indexed protected String terminologyClass; @Indexed(unique=true) protected String code; @Indexed protected String terminology; protected String notes; /

Mongodb performance difference between Hash and Ascending indices (Any reason not to use hash in a not ordered field?)

天涯浪子 提交于 2019-12-06 16:39:55
问题 In mongodb there are multiple types of index. For this question I'm interested in the ascending (or descending) index which can be used for sorting and the hash index which according to the documentation is "primarily used with sharded clusters to support hashed shard keys" (source) ensuring "a more even distribution of data"(source) I know that you can't create an index like: db.test.ensureIndex( { "key": "hashed", "sortOrder": 1 } ) because you get an error { "createdCollectionAutomatically

MongoDB Index optimization when using text-search in the aggregation framework

让人想犯罪 __ 提交于 2019-12-06 05:14:58
问题 We are building a simplified version of a search engine on top of MongoDB. Sample data set { "_id" : 1, "dept" : "tech", "updDate": ISODate("2014-08-27T09:45:35Z"), "description" : "lime green computer" } { "_id" : 2, "dept" : "tech", "updDate": ISODate("2014-07-27T09:45:35Z"), "description" : "wireless red mouse" } { "_id" : 3, "dept" : "kitchen", "updDate": ISODate("2014-04-27T09:45:35Z"), "description" : "green placemat" } { "_id" : 4, "dept" : "kitchen", "updDate": ISODate("2014-05-27T09

Slow range query on a multikey index

余生颓废 提交于 2019-12-06 01:03:56
问题 I have a MongoDB collection named post with 35 million objects. The collection has two secondary indexes defined as follows. > db.post.getIndexKeys() [ { "_id" : 1 }, { "namespace" : 1, "domain" : 1, "post_id" : 1 }, { "namespace" : 1, "post_time" : 1, "tags" : 1 // this is an array field } ] I expect the following query, which simply filters by namespace and post_time , to run in a reasonable time without scanning all objects. >db.post.find({post_time: {"$gte" : ISODate("2013-04-09T00:00:00Z

Mongodb performance difference between Hash and Ascending indices (Any reason not to use hash in a not ordered field?)

拜拜、爱过 提交于 2019-12-04 23:44:01
In mongodb there are multiple types of index . For this question I'm interested in the ascending (or descending) index which can be used for sorting and the hash index which according to the documentation is "primarily used with sharded clusters to support hashed shard keys" ( source ) ensuring "a more even distribution of data"( source ) I know that you can't create an index like: db.test.ensureIndex( { "key": "hashed", "sortOrder": 1 } ) because you get an error { "createdCollectionAutomatically" : true, "numIndexesBefore" : 1, "errmsg" : "exception: Currently only single field hashed index

Create a conditional TTL in mongo

故事扮演 提交于 2019-12-04 22:31:17
问题 There is a particular task I want to accomplish , but I am not finding any particular way to do that. Lets say I have an app that is used to send mails. I keep record of this mails in a collection in mongo. And using this app I can send mail right now or can schedule mails for future. The structure of documents in collection is like : { '_id' : 123456789, 'to_email' : 'xyz@gmail.com' 'from_email' : 'abc@gmail.com' 'subject': 'some subject' 'type' : '<1 if normal and 2 if scheduled>',

mongodb: Multikey indexing structure?

泪湿孤枕 提交于 2019-12-04 09:23:15
问题 I'm finding it hard to understand how exactly indexing is done on multikeys in mongodb. This is what I read about multikeys in mongodb docs on its website: 1) "Creating an index on an array element indexes results in the database indexing each element of the array" 2) "...will index all the tags on the document, and create index entries for "X", "Y" and "Z" for that document." So what exactly does it mean by index entries for that document? Does each doc remember the entries, in which case

Slow range query on a multikey index

为君一笑 提交于 2019-12-04 06:29:43
I have a MongoDB collection named post with 35 million objects. The collection has two secondary indexes defined as follows. > db.post.getIndexKeys() [ { "_id" : 1 }, { "namespace" : 1, "domain" : 1, "post_id" : 1 }, { "namespace" : 1, "post_time" : 1, "tags" : 1 // this is an array field } ] I expect the following query, which simply filters by namespace and post_time , to run in a reasonable time without scanning all objects. >db.post.find({post_time: {"$gte" : ISODate("2013-04-09T00:00:00Z"), "$lt" : ISODate("2013-04-09T01:00:00Z")}, namespace: "my_namespace"}).count() 7408 However, it

mongodb: Multikey indexing structure?

我只是一个虾纸丫 提交于 2019-12-03 02:01:37
I'm finding it hard to understand how exactly indexing is done on multikeys in mongodb. This is what I read about multikeys in mongodb docs on its website: 1) "Creating an index on an array element indexes results in the database indexing each element of the array" 2) "...will index all the tags on the document, and create index entries for "X", "Y" and "Z" for that document." So what exactly does it mean by index entries for that document? Does each doc remember the entries, in which case searching is gonna be a full table scan? Or is it the same b-tree index of mysql where each index entry

Mongo indexing on object arrays vs objects

本秂侑毒 提交于 2019-12-02 15:35:12
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 index db.contact.ensureIndex({'groups.id':1}); My question is in regard to functionality. What are the