Home > Mobile >  Golang - Getting multiple val using Mongo Distinct
Golang - Getting multiple val using Mongo Distinct

Time:10-07

I want to return values from collection one is a batch that should be distinct and another is a vendor. I am unable to get vendor values?

How to achieve this using Distinct, What should I use?

CodePudding user response:

I found a similar question on StackOverflow which was answered.

Well, db.collection.distinct returns an array of the distinct field values. If you want other fields in the collection, use the db.collection.aggregate query (use $group stage to get distinct values of a field, and then you can include other fields also).

Link to the solution example

  •  Tags:  
  • go
  • Related