Mongo native makeIndex does not create index

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

What am I doing wrong?

+5
source share
2 answers

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

You must call securityIndex on the database object, not on the collection. This is contrary to the JavaScript console.

+2
source

I had a similar problem and the problem was that I did not open the database before calling securityIndex. What I did was (coffee script)

db.collection('resources').ensureIndex {"$**": "text"}, {name: "email_index_text"},(err, indexName) ->
        console.log indexName
        console.log err
        db.close()

db.open (err,database) ->
    db.collection('resources').ensureIndex {"$**": "text"}, {name: "email_index_text"},(err, indexName) ->
        console.log indexName
        console.log err
        db.close()

. , .

0

All Articles