0

I am querying a MongoDB database from a shell, I have a query that returns documents:

{"events" : "A"}
{"events" : "B"}
{"events" : "C"}
{"events" : "C"}

I would like to format the return to just return the values like so:

{"events" : [A, B, C, C]}

1 Answer 1

2

$group can be used to get your expected result.

db.collection.aggregate(
   [
      {
        $group : {
           _id : null,
           events: { $push: "$events" }
        }
      }
   ]
)
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, I just couldn't figure out how to group duplicate values.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.