0

I have data like:

{ title : "Moby-Dick" ,
author : "Herman Melville" ,
published : 1851 ,
ISBN : 0451526996 ,
topics : [ "whaling" , "allegory" , "revenge" , "American" ,
"novel" , "nautical" , "voyage" , "Cape Cod" ]
}

I want to create index on topics like:

db.volumes.createIndex( { topics: 1 } )

How to use pymongo to create mongodb like this?

user504909
  • 9,119
  • 12
  • 60
  • 109

1 Answers1

0

On Python changes just a little bit then the console mode. Soo, you need to use something like this

my_collection.create_index([("mike", pymongo.DESCENDING),("eliot", pymongo.ASCENDING)])

In your case, your can use just(because ascending is default):

db.volumes.createIndex("topics")

Source: Pymongo Documentation

Sham Fiorin
  • 403
  • 4
  • 16