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.
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"
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With