in mongodb's cmd you use the command:
db.test2.createIndex({ "type" : 1, "amount" : 1, "loss" : 1, "price" : 1, "create_date" : 1 }, {unique:true})
in python i can write methods for the 'find_one' command easily ie:
@staticmethod
def find_one(collection, query):
return Database.DATABASE[collection].find_one(query)
however writing one to create an index throws an error, ie:
@staticmethod
def create_index(collection):
return Database.DATABASE[collection].createIndex({ "type" : 1, "amount" : 1, "loss" : 1, "price" : 1, "create_date" : 1 }, {unique:true})
gives the error:
return Database.DATABASE[collection].createIndex({ "type" : 1, "amount" : 1, "loss" : 1, "price" : 1, "create_date" : 1 }, {unique:true})
NameError: name 'unique' is not defined