const lookup = {
from: 'model',
let: {
_id: '$id'
},
pipeline: $.pipeline().match(dbCmd.expr($.eq(['$model_id', '$$id']))).done(),
as: 'models'
}

naka1205
- 发布:2022-01-29 11:24
- 更新:2022-01-29 11:50
- 阅读:407
【报Bug】uniCloud.database 的lookup 方法 let 参数设置主键 _id 时报错 【已解决】
分类:uniCloud
产品分类: uniCloud/App
示例代码:
操作步骤:
const db = uniCloud.database();
const dbCmd = db.command
const $ = dbCmd.aggregate
const lookup = {
from: 'table',
let: {
_id: '$id'
},
pipeline: $.pipeline().match(dbCmd.expr($.eq(['$model_id', '$$id']))).done(),
as: 'tables'
}
await db.collection('model').aggregate().lookup(lookup).match({_id:'1'}).end()
const db = uniCloud.database();
const dbCmd = db.command
const $ = dbCmd.aggregate
const lookup = {
from: 'table',
let: {
_id: '$id'
},
pipeline: $.pipeline().match(dbCmd.expr($.eq(['$model_id', '$$id']))).done(),
as: 'tables'
}
await db.collection('model').aggregate().lookup(lookup).match({_id:'1'}).end()
预期结果:
查询主表model与副表table, 主表主键ID为1的数据
查询主表model与副表table, 主表主键ID为1的数据
实际结果:
提示 ''_id' starts with an invalid character for a user variable name'
提示 ''_id' starts with an invalid character for a user variable name'
bug描述:
在使用关联查询时,一对多的情况下主表的主键ID无法定义在 let 属性中
提示 ''_id' starts with an invalid character for a user variable name'
糖醋排骨
怎么换名字?
2022-08-03 18:05