top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to find the indexes in MongoDB?

+2 votes
384 views

I have created some of the indexes in mongoDB, Now i want to see the indexes created in the DB.

posted Jul 1, 2015 by Prakash Singh

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+2 votes

From the shell:

db.test.getIndexes()
or 
db.collection.getIndexes()
or 
use "yourdbname"
db.system.indexes.find()

Refer
http://www.mongodb.org/display/DOCS/Indexes

answer Jul 1, 2015 by Salil Agrawal
Similar Questions
+3 votes

I need a tool for rapidly recreating the proper "schema" (such as it is) of MongoDB instances between environments that pre-creates the right DB names, collections, sets collection caps, and creates the indexes for each collection. I do NOT want to copy all of the data between the instances, though. Each env I manage has different data but the DB/collection/caps/indexes are all the same. Is there an easy way to do this, preferably a tool that exports a JSON doc of all the names, caps and indexes that can then be re-ported into a new instance?

Thanks in advance

+2 votes

I get duplicates of fields and subfield using aggregation. Searching for duplicated sub field "k01.v" works fine:

db.table_0.aggregate({"$group" : { _id: "$k01.v", "count": { "$sum": 1 } } }
{"$match": {"count" : {"$gt": 1} } }
{"$project": {"k01.v" : "$_id", "_id" : 0} });

Unfortunately, this doesnt work when searching for sub field "a1.0" (field "a1" is an array):

db.table_0.aggregate({"$group" : { _id: "$a1.0", "count": { "$sum": 1 } } }
{"$match": {"count" : {"$gt": 1} } }
{"$project": {"a1.0" : "$_id", "_id" : 0} });

Any workaround ?

+2 votes

I have an use case where I have find all the matching records and apply the aggregation like count, sum, group by etc .
Can I use such scenarios where I have to use find and aggregate function together or should I find then get the cursor object and have to perform aggregation operation separately

...