1

After some activities with my database, I lost my index. I had these indexes:

{
    "v" : 1,
    "key" : {
        "_id" : 1
    },
    "name" : "_id_",
    "ns" : "collection.statement"
},
{
    "v" : 1,
    "unique" : true,
    "key" : {
        "name" : 1
    },
    "name" : "name_1",
    "ns" : "collection.statement"
}

and now I have only first one. I've entered this command

db.collection.createIndex({
    "v" : 1, 
    "unique" : true, 
    "key" :{ "name" : 1 }, 
    "name" : "name_1", 
    "ns" : "collection.statement"
})

and I only get and error message that i have a bad index key pattern. Please, help me, how to return this index? What I do wrong?

1 Answer 1

2

Use this:

db.collection.createIndex( { "name": 1 }, { unique: true } )

You attempt includes internal aspects of the index ("v" : 1), you just need to supply the field(s) and an order for each and the unique instruction.

More details in the docs.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.