如何使用排序选项查询 MongoDB 聚合

Rob*_*uez 13 mongodb mongodb-query mongodb-atlas mongodb-stitch

我创建了一个“品牌”集合,然后collation: { locale: "en", strength: 2}在“标题”字段上添加了一个索引。但是当我尝试使用此排序规则查询它时,它无法按预期工作:

const query = brand => mongodb.db("my-db").collection("brands")
    .aggregate([
      { $match: { title: brand } },
      { $project: { _id: 0, total: 1, categories: { $slice: [ "$categories", 5 ] }, tags: { $slice: [ "$tags", 5 ] } } }
    ], { collation: { locale: 'en', strength: 2 } })
    .asArray();
Run Code Online (Sandbox Code Playgroud)

所以调用brand('Test')会给出结果,但brand('test')给出一个空列表。

当我使用 Atlas Aggregation Builder 尝试相同的查询时,两个查询都会给出相同的(非空)结果。有任何想法吗?