I have a question regarding Mongo shard keys. I have documents which are structured in the following way:
{
"payload": {
"id": "364e1f2c-6d4c-45fb-af19-841149286d67",
"name": "John",
},
"source": "myApp",
"version": "1.0",
"additionalInfo": {
"time": "2012-04-18T17:32:11+03:00"
}
}
I'd like my shard to key to be: payload.name and additionalInfo.time. The following command fails on syntax error:
db.runCommand({ shardcollection : "collection.table", key : {additionalInfo.time: 1, payload.name: 1}})
Is it possible to create such a shard key or only top level keys are acceptable. Additionally, if I try to insert a document which does not have the shard key fields, will the insert fail?
就是这样,你需要用引号括起你的关键字段:
db.runCommand({ shardcollection : "collection.table", key : {'additionalInfo.time': 1, 'payload.name': 1}})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.