Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Aug 152011
 

Creates an index in MongoDB

Answer:

In an given collection, if you want to add an index on a specify field, you can do the following in the mongodb Interactive shell.

db.test.ensureIndex( { name : 1 } )

The key "name" from now on will have index enabled.

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>