>>> client.indextest.source.create_index([('a', -1)], background=True)
u'a_-1'
>>> list(client.indextest.source.list_indexes())
[SON([(u'v', 1), (u'key', SON([(u'_id', 1)])), (u'name', u'_id_'), (u'ns', u'indextest.source')]), SON([(u'v', 1), (u'key', SON([(u'a', -1)])), (u'name', u'a_-1'), (u'ns', u'indextest.source'), (u'background', True)])]
>>> def clean_indexes(indexes):
... for index in indexes:
... if index['name'] == '_id_':
... continue
... index.pop('ns', None)
... yield index
...
>>> c.indextest.command('createIndexes', 'destination', indexes=[index for index in clean_indexes(c.indextest.source.list_indexes())])
{u'createdCollectionAutomatically': True, u'numIndexesAfter': 2, u'ok': 1.0, u'numIndexesBefore': 1}
>>> list(c.indextest.destination.list_indexes())
[SON([(u'v', 1), (u'key', SON([(u'_id', 1)])), (u'name', u'_id_'), (u'ns', u'indextest.destination')]), SON([(u'v', 1), (u'key', SON([(u'a', -1)])), (u'name', u'a_-1'), (u'ns', u'indextest.destination'), (u'background', True)])]
If you're going to store the indexes as JSON documents to restore later using python you *must* make sure the documents are JSON decoded to OrderedDict. This is necessary to preserve the order of the index keys. There is an example here: