Using motor module to access mongodb in python application.
In python code, calling find() on a non-existence collection got an empty result, which is perfect.
When calling insert() on a non-existence collection, motor will create the collection first, then insert the document in the collection. I’d want to add a unique index to the collection when it’s created by motor. Is there a method to implement this without writing code to check the existence of the collection and index, and create the collection and index explicitly before issuing insert() calls, like using configuration or adding extra metadata to the data passed in to the insert() call?