mongodb - MongoDB查询最相似的数组
问题描述
我在一个 MongoDB 集合中有一堆文档,这些文档有一个指纹,它由 8 个布尔值组成。我想构建一个查询,该查询将为我提供具有 7 到 8 个布尔值的文档,这些布尔值与我的查询以相同的顺序排列。
所以我的查询将是以下内容:查找所有具有
fingerPrint = ["true", "false", "true", "true", "true", "true", "false", "true" ]
该查询将返回两个文档,因为第一个文档在序列中的所有布尔值都是正确的,而第二个文档在序列中的 8 个布尔值中有 7 个是正确的。
{
"_id" : ObjectId("5538e75c3cea103b25ff94a3"),
"name" : "document1",
"fingerPrint" : [
"true",
"false",
"true",
"true",
"true",
"true",
"false",
"true"
]
},
{
"_id" : ObjectId("5538e75c3cea103b25ff94a4"),
"name" : "document2",
"fingerPrint" : [
"true",
"false",
"true",
"true",
"false",
"true",
"false",
"true"
]
}
我该怎么做呢?
或者:是否有更好的方法来存储位数组并能够更优化地查询集合?
解决方案
推荐阅读
- c++ - 使用字符串数组和整数数组按升序排列数组
- java - Android列表视图不适用于片段
- three.js - Three.js 错误:“未捕获的 TypeError:THREE.InstancedMesh 不是构造函数”
- powershell - PowerShell:检查 WIA (COM?) 对象是否具有特定属性
- node.js - 在使用 http-proxy-middleware 代理到 websocket 服务器之前,如何进行一些验证?
- html - SVG 对象匹配封面
- python - Dask Dataframes (Python):如何通过子文件运行计算?即如何利用底层文件结构?
- javascript - getuikit 模态根本不显示
- javascript - UnhandledPromiseRejectionWarning: DiscordAPIError: Invalid Form Body
- java - Gluon JavaFX maven nativerun 在加载 fxml 文件时出现错误