How to resolve references to documents in MongoDB

Suppose I have an aggregate pipeline which returns the following set of documents:

[
  { "_id": 0, "refs": [1, 2] }, 
  { "_id": 1, "refs": [2, 3] }
]

How do I extend the aggregate pipeline to

  1. collect the set of distinct values in "refs" (i.e. [1, 2, 3]) and
  2. return the documents with _id matching the values in that set (i.e. 3 documents with _id 1, 2, and 3).


Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation