MongoDB图查询性能测试
要使用图查询$graphLookup mongodb的版本必须在3.4以上
可以使用db.version()查看
现用官方给的例子测试:
db.employees.insert({ "name" : "Dev"})
db.employees.insert({ "name" : "Ron", "reportsTo" : "Eliot" })
db.employees.insert({ "name" : "Andrew", "reportsTo" : "Eliot"})
db.employees.insert({"name" : "Asya", "reportsTo" : "Ron"})
db.employees.insert({"name" : "Dan", "reportsTo" : "Andrew" })
db.employees.aggregate( [
{
$graphLookup: {
from: "employees",
startWith: "$reportsTo",
connectFromField: "reportsTo",
connectToField: "name",
as: "reportingHierarchy"
}
}
] )
相关文章