mongodb - 在 mongoDB 中查找以 16:xx:xx 开头的集合中的元素
问题描述
如果我想获取日期为 16:xx:xx 的元素 db.collection.find({"Date":/^16:/}) 以下元素应为:2020-09-24 16:00 :00 2020-06-10 16:01:30 2019-02-14 16:38:00 我怎样才能得到这样的结果?
解决方案
作为解决方案,您可以在搜索之前将日期投影到字符串,之后您可以轻松使用正则表达式来实现搜索,这是简单的示例
db.collection.aggregate(
[
{
$project: {
"d": { $dateToString: {format: "%Y-%m-%d", date: "$mydate"}},key:1
}
} ,
{
$match: {
d: /^16:/i
}
}
]
)
推荐阅读
- javascript - 循环遍历 JSON 文件的语法错误
- php - Laravel - 访问模型属性的不同方法
- c++ - 在没有 UAC 提示的受限用户帐户中以管理员身份运行进程
- parsing - 在 Vertica 中运行副本时面临连接问题
- pandas - 物流模型总结
- python - 使用 pandas 在同一图表中生成多个 scatter_matrix 图
- prolog - Prolog:测试 2 个列表的相似性
- python - Dataframe 有订阅购买历史。试图显示购买的后续订阅
- neutralinojs - 使用中性节点将文件写入特定目录
- c# - 使用场景管理器进行 Unity 倒计时