1

I have a collection depdata in MongoDb. This contains below json data:

1st document:

{
    "Type": "R1",
    "Score": "20"
}

2nd document:

{
    "Type": "R2",
    "Score": 340"
}

I am using python and connected to the database. I have to get the values of the variable Score from all the documents in the collection depdata. For this I can do below:

val = depdata_collection.distinct('Score')

and this gives me the values of all the Score in the collection as list. But here I want to apply the condition where Type should only be R2. How can I write query for this and get the values only where Type is R2. Thanks

S Andrew
  • 5,592
  • 27
  • 115
  • 237

1 Answers1

1

Use second argument in the distinct query

val = depdata_collection.distinct('Score', { "Type": "R2" })
Ashh
  • 44,693
  • 14
  • 105
  • 132