R
R
Rag'n' Code Man2020-07-20 22:09:29
MongoDB
Rag'n' Code Man, 2020-07-20 22:09:29

Why can't I create indexes in MongoDB?

Good evening, I want to create an index in my MongoDB database, but it is not created and throws out the following error: 5f15eb615dd9d877860928.jpeg

Here is the index creation code:

collection.createIndex({login: data[1]}, {unique: true}, (err, result) => { // data[1] хранит в себе значение поля login
       console.log(err, result)
})

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hzzzzl, 2020-07-20
@hzzzzl

data[1] stores the value of the login field

i.e. what does it store?
it seems like there you can only set login: -1 or login: 1
For an ascending index on a field, specify a value of 1; for descending index, specify a value of -1.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question