2

I am trying to show distinct values of two fields. Not sure it is possible to return values from the two fields in my Mongodb.

I have tried this:

db.sInsert.distinct("post_id","post_message").

But it is not possible to do so.

2
  • what do you mean by distinct value on two fields? Is post_id also stored in post_message? Or do you want distinct on combination of post_id and post_message? Commented Feb 6, 2018 at 8:41
  • Possible duplicate of How to efficiently perform "distinct" with multiple keys? Commented Dec 7, 2018 at 7:23

1 Answer 1

1

You can use $group in aggregation

db.sInsert.aggregate( [ {"$group": { "_id": { post_id: "$post_id", post_message: "$post_message" } } } ]);
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.