云数据库如何返回数组字段中特定符合条件的对象?

发布于 6 年前作者 chao678249 次浏览最后编辑 6 年前来自 ask

mydb表中每条记录格式如下:

每条记录中的data数组字段有200个对象,符合条件的对象可能只有几个

现在想一次查询返回200个完全符合条件的对象

const text = “红色”

期待返回:[3,200,…]

db.collection(‘mydb’).where({

'data.utag': new RegExp(text, 'i'),

}).field(‘data.id’).get()

会返回整个data字段中所有的id

请问各位大佬该如何写啊?

1 回复
minshao
minshao1 楼4 年前

aggregate.unwind