【发布时间】:2020-06-19 00:59:18
【问题描述】:
这种语法是查找任何对象“gt”日期或两个带有“lt”的日期之间,所以我这样做:
db.compte.aggregate([
{
$project: {
time: {
$filter: {
input: "$auditMessages",
as: "auditMessages",
cond: {
$and: [
{
$gt: ["$$auditMessages.timestamp", "2020-05-20T07:18:42.115Z"]
}
]
}
}
}
}
}
]);
这是结果,它有效:
{
_id: ObjectId"5ed638e566a699750cbb1b0f"),
time: [
{
eventCategory: "Audit",
objectType: "Audit Log",
eventAction: "Query",
status: "Initiated",
username: "Unknown",
userId: "Unknown",
timestamp: "2020-05-20T07:19:05.149Z",
eventDescription: "Querying without filters."
},
{
eventCategory: "Audit",
objectType: "Audit Log",
eventAction: "Query",
status: "Successful",
username: "Unknown",
userId: "Unknown",
timestamp: "2020-05-20T07:18:42.232Z",
eventDescription: "Querying without filters."
}
]
}
现在我想查找日、月和年,例如我想要这样的时间戳: 年份:2020 月:05 天数:20 小时:07 分钟:18 和毫秒:42
提前谢谢你。
【问题讨论】:
标签: arrays mongodb mongodb-query aggregation-framework