这是一次构建多个索引的延续,我目前正在使用以下命令
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})
我想了解将其转换为要在服务器上执行的单个命令的正确方法是什么。我的失败尝试如下:
#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
}
)