title: Ascending and descending not working while passing as argument in mongodb with python
body: <p>I am new to mongodb. And using it for a simple operation. I have created one collection named <strong>users</strong> in a database and it will have 2 fields as <strong>fName</strong> &amp; <strong>lname</strong>. Now using python (.py file) I am showing all records. The code is-</p>
  
  <pre><code>from pymongo import Connection
  from pymongo import ASCENDING, DESCENDING
  from sys import argv
  
  #making new connection
  connection = Connection()
  
  #mydb  is the database name
  db = connection.mydb
  
  # usersis the collection name
  collection = db.users 
  data = collection.find()
  
  if len(argv) &gt; 2:
     script, fieldname, sortOrder = argv
     data = collection.find().sort(fieldname,sortOrder)
  #printing data
  for each_data in data:
     print 'First Name: %s, Last Name: %s % (each_data['fname'],each_data['lname'])
  </code></pre>
  
  <p>Now the problem is that if I pass <strong>sortOrder</strong> as argument by command line, it doesn't take it and the result will be in normal way(without any sorting).</p>
  
  <p>So can we pass the 2nd arg of .sort() method as variable or we have to pass <strong>ASCENDING</strong>, <strong>DESCENDING</strong> directly.</p>
  
  <p>Can any one tell the solution. </p>