Şöyle yaparız
Açıklaması şöyle. $graphLookup için bazı kısıtlar var.db.nodes.aggregate([{ $match: { treeId: 1001, $and: [ { nodeId: 100 } ] } },{$graphLookup: {from: "nodes",startWith: "$nodeId",connectFromField: "nodeId",connectToField: "parentId",restrictSearchWithMatch: {"treeId": 1001},maxDepth: 10000as: "descendants"}}]);
We need the $match stage in order to filter the documents and pass only the documents that match the specified condition(s) to the next pipeline stage. In our case, we need to match a single document identified by its node Id and the tree it belongs to (identified by the tree Id). This is the document/node from which the $graphLookup stage will begin the recursion from. Have in mind that the filed parent Id can be an Array i.e. we can multiple parents for nodes. Although not demonstrated here, this is supported by $graphLookup.For a full list of options and the internals of the $graphLookup operation, it is highly recommended to check the official documentation here. Make sure you pay attention to the following noteworthy limitations including the following:1. The collection specified in from field cannot be shared. This is an important consideration, due to the fact that lack of sharding means lack of horizontal scalability. On the other hand, if we are dealing with a very large dataset dynamically increasing, then perhaps other storage engines should be considered for heavy graph-like operations.2. The $graphLookup stage must stay within the 100 megabyte memory limit.
Döndürülen sonuç için de bazı kısıtlamalar var. Açıklaması şöyle.
The results we get back from the pipeline execution are flat and no order is guaranteed.
Hiç yorum yok:
Yorum Gönder