This is in continuation to Building Multiple Indexes at Once, where I am currently making use of the following commands
db.test_collection_data.createIndex({"uId" : 1, "name" : 1}, {unique : 1})
db.test_collection_data.createIndex({"uId" : "hashed"})
db.test_collection_data.createIndex({"uId" : 1, "products" : 1})
db.test_collection_data.createIndex({"bId" : 1})
I want to understand what is the correct way of transforming this into a single command to be executed at the server. My failed attempts are as follows:
#uniqueness is lost for the first index
db.test_collection_data.createIndexes(
[
{"uId" : 1,"name":1},
{"uId" : "hashed"},
{"uId" : 1,"products":1},
{"bId" : 1}
]
)
#unable to create since products are not really unique
db.test_collection_data.createIndexes(
[
{"uId" : 1,"name":1},
{"uId" : "hashed"},
{"uId" : 1,"products":1},
{"bId" : 1}
],
{
unique: true
}
)
There is a answer provided the reference to createIndexes, The createIndexes command takes the form of
runCommand
: you could use, syntax and example,Your database name
and collection name intest_collection_data
,