I want to insert a record in MongoDB database but only if it does not exist there yet. Something tells me that this code is not optimal in terms of performance:
if db.foo.find(record).count() == 0:
db.foo.insert(record)
How to do it fastest way?