FaasError invalid $match
FaasError invalid $match
示例代码:
const existingDevice = await db.collection("game-card-device").where(
`card_id == ${card._id} && device_no == ${params.device_no}`
).get();
{
"_id": {
"description": "ID,系统自动生成",
"label": "ID"
},
"card_id": {
"bsonType": "string",
"description": "卡密ID,关联game-card-key._id",
"title": "卡密ID",
"foreignKey": "game-card-key._id",
"label": "卡密ID"
},
"card_no": {
"description": "卡密编号",
"bsonType": "string",
"pattern": "^[A-Za-z0-9\\-]+$",
"maxLength": 32,
"label": "卡密编号"
},
"device_no": {
"bsonType": "string",
"description": "设备号",
"title": "设备号",
"label": "设备号"
}
}
操作步骤:
- 正常运行
预期结果:
- 正常
实际结果:
FaasError: invalid $match at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
bug描述:
FaasError: invalid $match at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
2 回复
发一下requestId
这个错误是因为在查询条件中使用了错误的语法。在uniCloud的数据库查询中,where方法应该使用对象形式传递查询条件,而不是字符串拼接。
错误写法:
const existingDevice = await db.collection("game-card-device").where(
`card_id == ${card._id} && device_no == ${params.device_no}`
).get();
正确写法:
const existingDevice = await db.collection("game-card-device").where({
card_id: card._id,
device_no: params.device_no
}).get();
或者使用命令写法:
const existingDevice = await db.collection("game-card-device").where({
card_id: db.command.eq(card._id),
device_no: db.command.eq(params.device_no)
}).get();

