Questions tagged [graphlookup]

MongoDB aggregation operator, Performs a recursive search on a collection, with options for restricting the search by recursion depth and query filter.

Performs a recursive search on a collection, with options for restricting the search by recursion depth and query filter.

32 questions
6
votes
1 answer

Aggregation $graphLookup retrieving results in different order every-time the query is executed?

I have the following dataset (categories): [{ "_id": 1, "name": "Root", "parent": null }, { "_id": 2, "name": "Sub - Level 1", "parent": 1 }, { "_id": 3, "name": "Sub - Level 2", "parent": 2 }, { "_id": 4, "name":…
2
votes
1 answer

MongoDB $graphLookup until a condition is met (included)

I am looking for how to use $graphLookup and its match condition to return all nodes until a condition is met, including matches breaks the condition in the recursion stack. the first node that satisfies the condition in the recursion stack on each…
C. Claudio
  • 177
  • 13
2
votes
1 answer

How to list all items in the MongoDB on the tree structure?

Consider the structure like this: class Group { _id: ObjectId subGroups: ObjectId[] name: string info: string } A document for Group A in the database should be... _id: ObjectId("6092387f9c69970c20fe648a") subGroups: [ …
James Fu
  • 444
  • 1
  • 8
  • 21
1
vote
1 answer

MongoDB: Graphlookup nested documents only returns single document in aggregation

I'm trying the MongoDB aggregation framework to work with nested documents but having trouble returning the expected output, specifically in the $graphLookup stage. In a non-nested schema, it correctly looks up all the documents as defined in the…
Nugget
  • 81
  • 1
  • 6
  • 23
1
vote
1 answer

Cannot get parent data by mongoDB aggregate graphLookup

Following is the data [ { "_id": { "$oid": "6364f2eee35fc06fa06afb5f" }, "type": "subbranch", "parent_id": "635116c18fe4294398842ebb", "org_name": "Pune - Delhi" }, { "_id": { "$oid":…
conrad
  • 51
  • 8
1
vote
1 answer

mongodb aggregate to get recursively every parent of category by parent id

I tried to do it with graphLookup, but ended up with no result. Is it possible to do it with lookup only or I need to add more aggregation functions? My collection and expected result below My collection: [ { "_id": "62acec38aa7bfb93f882c7d5", …
1
vote
0 answers

How to sort results of graphLookup in subdocument

I have the following stage in my aggregation pipeline: { $graphLookup: { from: 'rateplans', startWith: '$ratePlans.parentRatePlanId', connectFromField: 'parentRatePlanId', connectToField: '_id', as:…
Mike
  • 23,542
  • 14
  • 76
  • 87
1
vote
0 answers

How to efficiently find linked items by path in MongoDB tree using $graphLookup?

I would like to find documents on a path in a tree structure in MongoDB using $graphLookup. For example, let's say I have this small structure: 0 - root └── 01 "home" ├── 011 "john" │ ├── 0111 "documents" │ └── 0112 "movies" …
Bartosz
  • 41
  • 3
1
vote
1 answer

mongodb graphLookup c# example with POCO classes

Is there any chance to use graphLookup aggregate stage with POCO classes and not bson documents? All examples I've found are using BsonDocuments and it makes me really confused. Thanks.
Daviid
  • 35
  • 5
1
vote
1 answer

Simplifying graphLookup output in MongoDB

I have a collection "people" in the form: { "_id" : 1, "name" : "Grandma"} { "_id" : 2, "name" : "Mum", "parentID": "1"} { "_id" : 3, "name" : "Uncle", "parentID": "1"} { "_id" : 4, "name" : "Kid", "parentID": "2"} { "_id" : 5, "name" :…
Edward Martin
  • 55
  • 1
  • 5
1
vote
2 answers

$graphLookup return void array

I have below collection: [{ "_id": "60035d0a1599912a5c814e58", "idUsuario": "600365521599912a5c814e5e", "parentNode": "", "piernaPadre": "", "estado": "1" }, { "_id": "6003827b06b4423c9ca7e6aa", "idUsuario":…
AndresChica
  • 155
  • 1
  • 13
1
vote
1 answer

Mongodb: Build category url with $graphLookup, $reduce & $concat in the right order

What i try to archive is to get a URL in the right order as the parents of an document. I generate this query: Input use('testdb'); db.categories.drop(); db.categories.insertMany([ { '_id' : 'shoes', 'name' : 'Shoes', 'path' : 'shoes', 'parent':…
Marcel
  • 199
  • 1
  • 18
1
vote
0 answers

Is there a way to minimize a $graphlookup output?

I am trying to get a hierarchy of competitors from a dataset in MongoDB, my code works as far as I can tell but the output is too difficult to read due to the size of the documents. I have looked into $project and trying to minimize the size of the…
1
vote
1 answer

Mongodb $graphLookup build hierarchy

I have an output from mongodb $graphLookup aggregation: db.getCollection('projects').aggregate([ { $lookup: { from: "projects", localField: "_id", foreignField: "parent", as: "childrens" } } ]) { "_id" :…
ricristian
  • 466
  • 4
  • 17
1
vote
1 answer

MongoDB aggregation $graphLookup - find "connections" in common in collections of following relationships

I have a collection of "who is following who" (like Instagram): db.users.insertMany([ { _id: 1, name: "Arnold Schwarzenegger" }, { _id: 2, name: "James Earl Jones" }, { _id: 3, name: "Harrison Ford" }, { _id: 4, name: "Jennifer Lawrence"…
Gianfranco P.
  • 10,049
  • 6
  • 51
  • 68
1
2 3