title: how to convert mongodb query to pymongo
body: <p>I have a collection of mongodb, which contains "MoviesID, UserID, Rating", so this is to describe the how the users rate different movies, and a user can rate different movies, and certainly a movie can be rated by different users. Now I want to find all the users who rate similar movies with target user. Rating similar movies means that they rate at least same movie, or more. My way is to find all the movies of target user, and then query for the users who also rate these movies. I have following mongo shell query, and it works: </p>
  
  <pre><code>var a = db.ratings.distinct("MovieID",{"UserID":"user"});
  db.ratings.distinct("UserID",{"MovieID":{$in:a}}))
  </code></pre>
  
  <p>but because I want an input, i tried pymongo to get input, my code is: </p>
  
  <pre><code>import sys
  import pymongo
  import re
  import codecs
  
  from pymongo import MongoClient
  client = MongoClient()
  
  db = client['moviesdb']
  
  user = input("Enter the user: ")
  
  # #ratings = db.ratings
  
  from bson.son import SON
  
  
  
  import pprint
  
  a = db.ratings.distinct("MovieID",{"UserID":"user"});
  pprint.pprint(db.ratings.distinct("UserID",{"MovieID":{"$in":a}}));
  </code></pre>
  
  <p>but the result is an empty array, I do not know why. So what's the problem with the pymongo code? Or is there any way to get an input in shell so i do not need to write Pymongo?   Thanks!</p>