Home > OS >  How to use collation in mongoc.jl?
How to use collation in mongoc.jl?

Time:02-05

I want to do a diacritic-insensitive and case-insensitive search in mongo. In Python this can be done using collation:

db['cities'].find_one({'name': 'Bogota'}).collation({'locale': 'en_US', 'strength': 1 })

There is apparently no equivalent method in mongoc.jl, or if there is I haven't seen it in the docs. I tried putting it in the BSON string:

data = Mongoc.find(db["cities"], Mongoc.BSON(""" {"name": "Bogota"}, {"collation":{"locale":"en_US", "strength":1}}"""))

Returns an empty cursor, while putting the same query in mongosh does return results.

CodePudding user response:

https://felipenoris.github.io/Mongoc.jl/stable/api/#Mongoc.find says

find(collection::Collection, bson_filter::BSON=BSON();
    options::Union{Nothing, BSON}=nothing) :: Cursor

so it must be

data = Mongoc.find(db["cities"], Mongoc.BSON(""" {"name": "Bogota"}"""); 
    Mongoc.BSON("""{"collation":{"locale":"en_US", "strength":1}}"""))
  •  Tags:  
  • Related