array-index的结构如下:
{
"addr": [
{
"id": "1111"
},
{
"id": "1111"
}
],
"name": "测试名称",
"nextseq": "$seq",
"seq": 3
}
const db = uniCloud.database();
const doc = db.collection('array-index');
const dbCmd = db.command
const res = await doc.where({
id:'5e7464822fe447004d49617a',
addr: dbCmd.elemMatch({
id: dbCmd.neq(nextid)
})
}).update({
'addr': dbCmd.push({
id: nextid,
name: '测试'
})
})
上传并运行云函数,爆出
errCode: InternalServerError | errMsg: 云数据库系统错误 << unknown operator: $neq
Error: errCode: InternalServerError | errMsg: 云数据库系统错误 << unknown operator: $neq
at e.then.catch.e (/tmp/function/@dcloudio/serverless/lib/aliyun/uni-cloud.js:1:1025)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
我是MongoDB的初学者,我有看uniCloud文档,这样是哪个地方出问题了吗?
顺便在问下,如何自定义索引,比如addr
是一个对象数组字段,那么如何支持id
唯一呢,我在后台那边配置好像没有效果
但是我换成eq
则可以运行:
const db = uniCloud.database();
const doc = db.collection('array-index');
const dbCmd = db.command
const res = await doc.where({
id:'5e7464822fe447004d49617a',
addr: dbCmd.elemMatch({
id: dbCmd.eq('1111')
})
}).update({
'addr': dbCmd.push({
id: nextid,
name: '测试'
})
})
则成功插入:
{
"addr": [
{
"id": "1111"
},
{
"id": "1111"
},
{
"id": "OITonzrZR",
"name": "测试"
}
],
"name": "测试名称",
"nextseq": "$seq",
"seq": 3
}
2 个回复
DCloud_uniCloud_WYQ
已确认Bug,感谢反馈
DCloud_uniCloud_WYQ
2.6.15已修复此问题