title: How to filter data in mongo collection using pymongo
body: <p>I am using pymongo to query MongoDB and check duplicates in a particular collection. I have identified the duplicates but I want to add one more filter to the script. Please find my script below</p>
  
  <pre><code>from pymongo import MongoClient
  
  
  client = MongoClient ('localhost')
  db = client.test
  
  data = db.devices.aggregate([
      {'$group': {'_id':{'UserId':"$userId",'DeviceType':"$deviceType"},
                  'count':{"$sum":1}}}, 
      {'$match': {'count' : {"$gt" : 1}}}
  ])
  
  for _id in data:
      print _id
  </code></pre>
  
  <p>From the above script, I want to check duplicates only for the data where the DeviceType = "email". I have tried adding an "and" condition after the match but it didn't work.</p>
  
  <p>Could you please let me know how to achieve that?</p>
  
  <p>Thanks</p>