mongodb - 构建 MongoDB 索引以覆盖所有类型的查询的最佳方法
问题描述
我正在构建一个查询引擎,其底层数据库是 DocumentDB(又名 MongoDB 3.6),我想知道为它构建索引的最佳方法是什么,以获得最佳的查询性能。虽然肯定会有某些查询比其他查询更常见,但事实上用户将构建这些查询,目标是在查询的任何属性组合中具有良好(足够)的性能。
此集合中的文档将具有类似于以下的结构:
{ "ContainerName" : "hello",
"description" : "test",
"timestamp" : 1000000,
"isActive" : true,
(15 more attributes of strings, booleans, numbers),
"events": [
{ "eventId" : "test",
(10 more attributes of strings, booleans, numbers)
},
{ "eventId" : "test2",
(10 more attributes of strings, booleans, numbers)
}],
"resources": [
{ "resourceId" : "test",
(8 more attributes of strings, booleans, numbers)
}]
}
我希望能够查询所有属性组合,包括嵌入式属性。例如,给我一个名为 hello 的容器,它有一个带有 test 的 eventId 的事件。如果属性的数量足够少,也许我可以将所有可能的组合作为复合键,但在这里不可能。
此外,如果我想在某些字段上对字符串包含使用正则表达式,MongoDB 是否会在它可以使用的过滤器属性上使用索引,然后手动过滤以完成正则表达式,或者使用正则表达式完全消除对查询的索引的使用。
解决方案
推荐阅读
- manim - 更改图形的整体比例
- javascript - Javascript承诺执行时间问题
- github - 如果文件未被触及,如何触发 Github 操作?
- c - 如何解决 DPDK 内存池创建失败?
- javascript - 如何使用javascript填充从文本框中选择的下拉列表中的值
- json - 无法将响应数据分配给状态数据并且响应在 React 中不为空
- python-3.x - 即使不在列表中,在列表中获取重复项也应该在 Python 中正常工作
- google-smart-home - 当用户选择取消链接时该怎么办
- python - Python 和 Pandas 中的年月彩条图
- sql-server - SQL Server 中不存在约束