mongodb - 如何使用排序选项查询 MongoDB 聚合
问题描述
我创建了一个“品牌”集合,然后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();
所以调用brand('Test')
会给出结果,但brand('test')
会给出一个空列表。
当我使用 Atlas Aggregation Builder 尝试相同的查询时,两个查询都会给出相同的(非空)结果。有任何想法吗?
解决方案
推荐阅读
- excel - 带有双重匹配的 COUNTIFS
- python - 并行运行 Binance websocket
- kotlin - Null 安全地检查 kotlin 格式
- kofax - 是否可以使用 KTA SDK 合并图像文件?
- r - Cbind 数据框并使用粘贴输出以创建标签
- javascript - Vue.js:带换行符的字符串插值
- python - 在 Pandas 中组合列并连接非缺失值
- python - 在python中创建一个监听来自套接字连接的消息的程序
- ios - 物理 IOS / Android 设备上的 Firebase Firestore 模拟器
- python - 为什么我在 Python 中的正则表达式不能正常工作?