【问题标题】:mongodb graphLookup not working in sharded collectionmongodb graphLookup 在分片集合中不起作用
【发布时间】: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


【解决方案1】:

来自 MongoDB 3.4 以来的文档 (source):

The collection can be sharded.
The fromCollection cannot be sharded.

编辑 (source2):

support for sharded "from" collections in $lookup and $graphLookup will be part of the upcoming 5.1 release.

【讨论】:

  • 我已经在我的问题中提到了它...,但是搜索选项来解决它...
  • 我认为除了您拥有的或 Alex Blex 给出的答案之外,您的问题不太可能得到答案。除非您根据 Alex 的建议更改数据,否则您基本上希望文档不正确或开发人员没有找到秘密方法,这不太可能。您可以在此处监控此功能的进度:jira.mongodb.org/browse/…
  • 有更新:support for sharded "from" collections in $lookup and $graphLookup will be part of the upcoming 5.1 release.
猜你喜欢
  • 2021-07-26
  • 2013-08-31
  • 2018-12-15
  • 1970-01-01
  • 1970-01-01
  • 2012-05-10
  • 1970-01-01
  • 2021-08-21
  • 2021-07-14
相关资源
最近更新 更多