1

I want to make the same operation like this to return an array of strings:

model.find().distinct("some_field")

How it's possible to take the same result using aggregation function?

1 Answer 1

2

You can use below code to get all unique some_field using aggregate:

model.aggregate([
    {
        $group:{
           _id: null,
           some_field: { $addToSet: '$some_field' }
        }
    }
]);
Sign up to request clarification or add additional context in comments.

Comments

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.