it doesn't work :
> db.toto.find()
{ "_id" : ObjectId("4fc8cbdd3c2c5c4ccf30d582"), "author" : "Simon", "title" : "toto" }
> db.toto.aggregate( { $match : { author : "Simon" , title: { $substr :["t",1,1] } } } );
{
"errmsg" : "exception: invalid operator: $substr",
"code" : 10068,
"ok" : 0
}
my goal is to get a group by with the first letter of a field, example :
> db.toto.find()
{ "author" : "Simon", "title" : "toto" , nb :5 }
{ "author" : "Simon", "title" : "toto" , nb :2 }
{ "author" : "Simon", "title" : "azerty" , nb :12 }
{ "author" : "Simon", "title" : "azerty" , nb :5 }
I want to have :
Simon, t , 7
Simon , a , 17
what I tried :
db.toto.aggregate(
{ $group : {
_id : {author : "$author",titre : { $substr :["$title",0,1] } },
sum : { $sum : "$nb" }
}}
);
And that works really fine,
thank you :)