connectFromField of $graphLookup被记录为接收数组:https://docs.mongodb.com/manual/reference/operator/aggregation/graphLookup/
字段名,其值$graphLookup用于递归匹配集合中其他文档的connectToField。如果该值是一个数组,则每个元素将在遍历过程中被单独跟踪。
但是,在每个版本的MongoDB上,我都尝试过--当提供了一个字符串数组时,它失败了:
Error:
Uncaught exception: Error: command failed: {
"ok" : 0,
"errmsg" : "expected string as argument for connectFromField, found: [ \"name\", \"id\" ]",
"code" : 40103,
"codeName" : "Location40103"
} : aggregate failed :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
doassert@src/mongo/shell/assert.js:18:14
_assertCommandWorked@src/mongo/shell/assert.js:583:17
assert.commandWorked@src/mongo/shell/assert.js:673:16
DB.prototype._runAggregate@src/mongo/shell/db.js:266:5
DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1012:12
DBCollection.prototype.aggregate@:1:355
@(shell):1:1示例查询:
db.getCollection('sensor_data').aggregate([{$graphLookup: {
from: 'sensor_data',
startWith: 'name',
connectFromField: ['name', 'id'],
connectToField: 'value',
as: 'children'
}}])我是做错了什么,还是connectFromField值根本不接受数组?
发布于 2020-11-18 18:56:22
所引用的“值”是要遍历的文档中指定字段的值。不能指定多个字段名。
https://stackoverflow.com/questions/64897836
复制相似问题