【发布时间】:2021-06-03 06:11:33
【问题描述】:
我的 testcol 集合如下所示:
mongos> db.testcol.find().limit(3)
{ "_id" : ObjectId("60b871854bea7a9df54f0594"), "ID" : "B1", "CID" : "B2", "DOC" : "Some info" }
{ "_id" : ObjectId("60b8718e4bea7a9df54f0595"), "ID" : "B3", "CID" : "B5", "DOC" : "Some info" }
{ "_id" : ObjectId("60b871994bea7a9df54f0596"), "ID" : "B5", "CID" : "B2", "DOC" : "Some info" }
mongos>
在对 testcol 进行分片后,我意识到 $graphLookup 不再工作了:
mongos> db.testcol.aggregate([ { $graphLookup: { from: "testcol", startWith: "B1" ,
connectFromField: "ID", connectToField: "CID", as: "children" } } ])
2021-06-03T07:35:13.242+0200 E QUERY [js] Error: command failed: {
"ok" : 0,
"errmsg" : "test.testcol cannot be sharded",
"code" : 28769,
"codeName" : "Location28769",
"operationTime" : Timestamp(1622698513, 28),
"$clusterTime" : {
"clusterTime" : Timestamp(1622698513, 28),
"signature" : {
"hash" : BinData(0,"RObEDuuK9uibPFj/MAoDwSyR3Lc="),
"keyId" : NumberLong("6939965305435193347")
}
}
} : aggregate failed :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
doassert@src/mongo/shell/assert.js:18:14
_assertCommandWorked@src/mongo/shell/assert.js:580:17
assert.commandWorked@src/mongo/shell/assert.js:673:16
DB.prototype._runAggregate@src/mongo/shell/db.js:260:9
DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1062:12
@(shell):1:1
mongos>
根据 mongo docs $graphLookup 不接受来自分片集合,但是 我的集合变得非常大(已经 6TB),似乎我无法保持它不分片,关于如何在分片集合中获取我的图形关系的任何建议?
【问题讨论】:
-
只有 2 个选项 - 不分片或不使用 $graphLookup。我猜你的情况是后者。您需要在应用程序级别实现此功能。
标签: mongodb mongodb-query