mongodb $regex error: unknown operator -
i'm trying check 1st character of field not a-z
db.zips.aggregate( [ { $group : { city: { $regex: '^[a-z]', $options: 'i' }, n : {$sum:1} } } ] )
here sample doc expected found query errors unknown operator '$regex'. mongodb v2.4.5 installed:
{"city": "25536", "loc": [-82.076761, 38.087553], "pop": 61, "state": "wv", "_id": "25536"}
error:
error: printing stack trace @ printstacktrace (src/mongo/shell/utils.js:37:15) @ dbcollection.aggregate (src/mongo/shell/collection.js:897:9) @ (shell):1:9 wed jul 31 12:14:14.737 javascript execution failed: aggregate failed: { "errmsg" : "exception: unknown group operator '$regex'", "code" : 15952, "ok" : 0 } @ src/mongo/shell/collection.js:l898
thanks!
p.s. tried also:
db.zips.aggregate( [ { $project : { city: /^[a-z]/i }} ,{ $group : { city : "$city", n : {$sum:1} } } ] ) error: printing stack trace @ printstacktrace (src/mongo/shell/utils.js:37:15) @ dbcollection.aggregate (src/mongo/shell/collection.js:897:9) @ (shell):1:9 wed jul 31 12:26:21.531 javascript execution failed: aggregate failed: { "errmsg" : "exception: disallowed field type regex in object expression (at 'city')", "code" : 15992, "ok" : 0 } @ src/mongo/shell/collection.js:l898
so appears ways i'm trying use regex incorrect or in incorrect places/operations.
$regex cannot used there, want watch jira this: https://jira.mongodb.org/browse/server-8892
however, think want $match
regex instead of group. want match cities in criteria , wanna group them.
as reference here duplicate question found googling: using $regex in mongodb aggregation framework in $group
Comments
Post a Comment