我有一份这样的文件:
{
"_id" : ObjectId("52f29f91ddbd75540aba6dae"),
"teams" : [
{
"name" : "Washington Bullets",
"score" : 100,
"home" : false,
"won" : 1,
"players" : [
{
"player" : "Jeff Ruland",
"pts" : 19
},
{
"player" : "Cliff Robinson",
"pts" : 22
},
{
"player" : "Gus Williams",
"pts" : 21
},
{
"player" : "Jeff Malone",
"pts" : 18
},
{
"player" : "Charles Jones",
"pts" : 4
},
{
"player" : "Dan Roundfield",
"pts" : 2
},
{
"player" : "Perry Moss",
"pts" : 7
},
{
"player" : "Dudley Bradley",
"pts" : 0
},
{
"player" : "Darren Daye",
"pts" : 5
},
{
"player" : "Tom McMillen",
"pts" : 2
},
{
"player" : "Manute Bol",
"pts" : 0
}
]
},
{
"name" : "Atlanta Hawks",
"score" : 91,
"home" : true,
"won" : 0,
"players" : [
{
"player" : "Dominique Wilkins",
"pts" : 32
},
{
"player" : "Tree Rollins",
"pts" : 9
},
{
"player" : "Cliff Levingston",
"pts" : 8
},
{
"player" : "Spud Webb",
"pts" : 12
},
{
"player" : "Kevin Willis",
"pts" : 13
},
{
"player" : "Randy Wittman",
"pts" : 6
},
{
"player" : "Scott Hastings",
"pts" : 4
},
{
"player" : "Lorenzo Charles",
"pts" : 4
},
{
"player" : "Sedric Toney",
"pts" : 0
},
{
"player" : "Ray Williams",
"pts" : 0
},
{
"player" : "Jon Koncak",
"pts" : 3
}
]
}
]
}我想用teams.name碎。我试着做:
sh.shardCollection("finalNBA.list", {teams:{name:1}})但我得到的错误是,碎片键只能是1或散列。有人知道如何使用嵌入式字段启用分片吗?
发布于 2019-03-25 03:59:30
尝试使用,这里的关键是点符号。
sh.shardCollection("finalNBA.list", {"teams.name":1}})
确保您已经为test.name字段创建了索引。
https://dba.stackexchange.com/questions/232967
复制相似问题