我的测试控制台显示Command failed with error 15952 (Location15952): 'unknown group operator '$literal'' on server 172.28.207.10:3717. The full response is { "operationTime" : { "$timestamp" : { "t" : 1771778033, "i" : 40 } }, "ok" : 0.0, "errmsg" : "unknown group operator '$literal'", "code" : 15952, "codeName" : "Location15952", "$clusterTime" : { "clusterTime" : { "$timestamp" : { "t" : 1771778033, "i" : 40 } }, "signature" : { "hash" : { "$binary" : "L7wNzXT7d07VljCMfjWCPZfgk54=", "$type" : "00" }, "keyId" : { "$numberLong" : "7574829478296158258" } } } }
Error: Command failed with error 15952 (Location15952): 'unknown group operator '$literal'' on server 172.28.207.10:3717. The full response is { "operationTime" : { "$timestamp" : { "t" : 1771778033, "i" : 40 } }, "ok" : 0.0, "errmsg" : "unknown group operator '$literal'", "code" : 15952, "codeName" : "Location15952", "$clusterTime" : { "clusterTime" : { "$timestamp" : { "t" : 1771778033, "i" : 40 } }, "signature" : { "hash" : { "$binary" : "L7wNzXT7d07VljCMfjWCPZfgk54=", "$type" : "00" }, "keyId" : { "$numberLong" : "7574829478296158258" } } } }
at /tmp/function/@dcloudio/serverless/lib/aliyun/uni-cloud.js:1:1580
at processTicksAndRejections (node:internal/process/task_queues:96:5)
d***@qq.com
- 发布:2026-02-23 00:42
- 更新:2026-02-23 00:42
- 阅读:11
1 个回复
Ask小助手 - Ask社区AI助手
你遇到的
unknown group operator '$literal'报错,是因为 阿里云 MongoDB 4.0 及以下版本不支持在$group阶段使用$literal。虽然
$literal本身是合法的聚合操作符,但它只能用于$project、$addFields等阶段;一旦出现在$group里,低版本实例就会直接抛 15952 错误。为什么会“之前可以正常运行”
$group里用$literal;如何确认
解决办法(任选其一)
改写聚合语句
把
$group里的$literal挪到$project或$addFields阶段,例如:升级数据库版本
在控制台「云数据库 → 配置变更」里把实例升到 MongoDB 4.2 或更高版本,即可继续用原来的
$literal写法。升级过程约 1-3 分钟,期间会有一次闪断。临时绕过
如果暂时不能升级,也改不动代码,可以把
$literal换成$first或$max等兼容操作符,只要语义一致即可。总结
报错并非代码本身错误,而是 阿里云 MongoDB 版本差异 导致。按上面任一方案处理即可恢复。
要回复问题请先登录或注册
公告
更多>相关问题