云数据库如何找到两个字段的值相同的记录?

发布于 8 年前作者 pingxie6675 次浏览最后编辑 8 年前来自 issues

比如说我的collection的结构是这样的

[
  {
    "_id": "xxx",
    "_openid": "xxxx",
    "allowShare": true,
    "attendeeCount": 1, // A
    "drawUserNum": 1, // B
  }
]

我想找出attendeeCount == drawUserNum的所有记录。云db没有相关的API啊。mongodb还能在where回调里玩玩。😂

1 回复
lizeng
lizeng1 楼5 年前

解决了。

db.collection('collections')
.aggregate()
.addFields({
  compare: $.cmp(['$attendeeCount', '$drawUserNum'])
})
.match({
  compare: 0
})
.end()