示例代码中书写错误
发布于 5 年前 作者 na69 249 次浏览 来自 官方Issues

https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.elemMatch.html

示例代码:数组元素都是普通数据类型的情况

假设集合示例数据如下:

{
  "_id": "a0",
  "scores": [60, 80, 90]
}

找出 scores 数组字段中至少同时包含一个满足 “大于 80 且小于 100” 的元素

const _ = db.command
db.collection('todos').where({
  places: _.elemMatch(_.gt(80).lt(100))
})
.get()

places应该为scores,正确写法:
const _ = db.command
db.collection('todos').where({
  scores: _.elemMatch(_.gt(80).lt(100))
})
.get()

回到顶部