1

I can't figure out how i set default language from Python/Pymongo.

From the mongo console I can create the Index that I want like this:
>> db.collection.createIndex({"column1": "text", "column2": "text"}, {"default_language": "none"})

From Python/Pymongo I can create the same text index, but without the "default_language" like this:
collection.create_index([("column1", "text"), ("column2", "text")])

I would like to set default_language also from the Pymongo call. How do I do that syntactically?

  • https://pymongo.readthedocs.io/en/stable/api/pymongo/collection.html#pymongo.collection.Collection.create_index – D. SM May 27 '20 at 18:04

1 Answers1

1

It's semi-documented; the documentation states:

See the MongoDB documentation for a full list of supported options by server version.

So it's as straightforward as passing it as an additional argument:

from pymongo import MongoClient, TEXT

db = MongoClient()['mydatabase']
db.mycollection.create_index(name='index1', keys=[('column1', TEXT), ('column2', TEXT)], default_language='none')
Belly Buster
  • 8,224
  • 2
  • 7
  • 20
  • Happy to help. Don't forget to make helpful answers as accepted, it's useful to the next person that has the same issue. – Belly Buster Jun 02 '20 at 11:58