【发布时间】:2020-12-29 17:52:46
【问题描述】:
我需要为三个不同的字段获取三个不同的值列表,但我想避免多次查询数据库。我确定它使用 mongodb 聚合框架的答案,但是,我不确定如何使用它来选择不同的字符串列表?
tags: [{ type: String }],
categories: [{ type: String }],
hashtags: [{ type: String }],
...
let tags = await Model.distinct('tags');
let categories = await Model.distinct('categories');
let hashtags = await Model.distinct('hashtags');
【问题讨论】:
标签: mongodb mongoose aggregation-framework