Mongo collation

270 views
Skip to first unread message

Vincent Jouglard

unread,
Jul 18, 2017, 5:55:34 AM7/18/17
to mgo-users
Hi there,

I'm trying to have case insensitive $match in an aggregate pipe.
Mongo 3.4 allows :


db
.collection.aggregate([
{
   
"$match":{
       
"country":"France"
       
}
}],{collation:{locale:"en",strength: 2}}
)

which works like a charm, working with "France" and "france" especially.

I can't get to use Collation with mgo.v2 . Could someone give me a usage example ?

 o1 := bson.M{
   
"$match": bson.M{
       
"country":         country,
   
},
 
}

 collator
:= mgo.Collation{
   
Locale:    "en",
   
Strength: 2,
 
}
 operations
:= []bson.M{o1}
 pipe
:= c.Pipe(operations)

I actually don't even know what to do with this collator...!

Thanks a lot,

Gustavo Niemeyer

unread,
Jul 18, 2017, 10:16:58 AM7/18/17
to mgo-...@googlegroups.com

The two commands being executed there are pretty different: the one being executed in the shell passes the collation as a second argument to the aggregate function, not as part of the aggregation pipeline list itself as done in the second case. That's an additional "options" parameter into the function.

We support that in mgo as well, but we miss the collation field that was introduced in 3.4. It should look something like this:

    pipe := collection.Pipe(pipeline).Collation(&c)



--
You received this message because you are subscribed to the Google Groups "mgo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mgo-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Vincent Jouglard

unread,
Jul 18, 2017, 10:42:04 AM7/18/17
to mgo-users
Hi Gustavo,

Thanks for the answer, this sounds great.
I know you are busy, but do you have any idea of when this could be available in mgo ? Orelse, any workaround that I could use ?

Thanks a lot,
To unsubscribe from this group and stop receiving emails from it, send an email to mgo-users+...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Diego Medina

unread,
Jul 19, 2017, 3:32:17 PM7/19/17
to mgo-users
On my cell now but if you vendor mgo, which I would recommend, you can probably use this other pr as inspiration
https://github.com/go-mgo/mgo/pull/461

There I added hint to the count query

Reply all
Reply to author
Forward
0 new messages