FastFoodCoding

Login


Connect with one of the following accounts





Login

Please wait while we redirect...

Views: 350 Ask New Question


How to create MongoDB indexes on single field and multiple fields?

On By


1 Answer


1. Creating on one field

You can use the following syntax to create index on one field

db.collection.createIndex(field, options);

Ex.

db.users.createIndex( {name : 1}, {} );

1. Creating on multiple fields

You can use the following syntax to create index on multiple fields

db.collection.createIndex(fields, options);

Ex.

db.users.createIndex( {name : 1, age:  1}, {});
On By


Answer This Question


Top Tutorials

Top Questions

Top Articles

Top Blogs

Top News