微信小程序云数据库模糊查询实现一对一聊天
·
微信小程序云数据库模糊查询
示例:一对一聊天,查找自己对应了哪些聊天室
前提:房间ID=我的ID+你的ID;
实现:根据房间ID把房间分组 再模糊查询找到自己的ID在房间ID里的分组作为自己的聊天室
mygroup() {
const $ = db.command.aggregate
db.collection('newchatRoom')
.aggregate()
.match({
'groupId.RoomID': {
$regex: '.*' + this.openid + '.*', //.*等同于SQL中的%
$options: 'i' //$options:'1' 代表这个like的条件不区分大小写,详见开发文档
}
})
.group({ //按groupID分组
_id: '$groupId',
num: $.sum(1)
})
.end({
success: res => {
console.log(res.list)
this.RoomList = res.list;
for (let i = 0; i < res.list.length; i++) {
console.log(res.list[i]._id.RoomID)
}
}
})
},
!!!!!!!一定要打开权限

更多推荐


所有评论(0)