0

I am a complete beginner in mongodb. I want to do the mongodb equivalence of sql select distinct column. i.e. For a mongodb collection with the following schema:

{
    "_id" : ObjectId("xxxxxxcbf"),
    "date" : "1462514997209",
    "user_ids" : [ 
        "userXXXX"
    ],  
    "created" : 1462543716,
    "processed" : 1462543716
}

How to find unique user_ids in the collection?

DougKruger
  • 4,424
  • 14
  • 41
  • 62

1 Answers1

1

You need to use distinct() like (assuming your collection name is collection1)

db.collection1.distinct( "user_ids" )
Rahul
  • 76,197
  • 13
  • 71
  • 125