12

I have a database of English words stored in the field 'h'. I've just found out about text indexes and I wanna create one on this field to speed up searching by regex, but somehow, I just can't get the syntax right. I'm using pymongo 2.7.1 and python 3.4.

 from pymongo import MongoClient
 from pymongo import ASCENDING
 from pymongo import DESCENDING
 from pymongo import TEXT
 #...
 collection.create_index('h', TEXT)

And I'm getting the following error:

in create_index
raise TypeError("cache_for must be an integer or float.")
TypeError: cache_for must be an integer or float.

Note that ASCENDING and DESCENDING work. Also I'd like to set the default language as English.

thehousedude
  • 611
  • 6
  • 16

1 Answers1

15

Sending it as an array worked.

collection.create_index([('h', TEXT)], default_language='english')

I've also used collection.getIndexes() to check it:

    {
    "key" : {
        "h" : "text"
    },
    "ns" : "a.a",
    "name" : "h_text"
}
thehousedude
  • 611
  • 6
  • 16