Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongo native ensureIndex does not create index

I am using the mongodb native driver for node. I call ensureIndex({ keywords: 1}) after retrieving the collection. When I check in the mongo console, nothing appears when I call db.mycol.getIndexes().

What am I doing wrong?

like image 212
Derrick Mcmillen Avatar asked Nov 04 '22 23:11

Derrick Mcmillen


1 Answers

The API docs helped a little: http://mongodb.github.com/node-mongodb-native/api-generated/db.html#ensureindex

You're supposed to call ensureIndex on the database object, not the collection. This contradicts the JavaScript console.

like image 179
Alex Avatar answered Nov 11 '22 06:11

Alex