I need to filter the occurrences of the last hour of the next mongodb query;
db.OPERATIONS.find({"Description":"Not playable."}).count()
Thank you very much in advance.
Greetings.
I need to filter the occurrences of the last hour of the next mongodb query;
db.OPERATIONS.find({"Description":"Not playable."}).count()
Thank you very much in advance.
Greetings.
assuming you do not have the fecha
field in the Collection, I'll tell you that with the ObjectId you can have the date that the application was registered you can see it in the following way:
ObjectId.getTimestamp()
Once this has been clarified, the next thing is to look for the records of the last hour ( one hour apart from the current one ); you must calculate the last hour and compare it with the timestamp
of the ObjectId () , the difference is that we can not do it directly, we must use the function $ where to be able to calculate the date
You can make the following query:
db.OPERATIONS.find({
$where:
function() {
var ultimaHora = new Date();
ultimaHora.setHours(ultimaHora.getHours() - 1);
return this.Description == "Not playable" && this._id.getTimestamp() >= ultimaHora
}
}).count()
See if I understood well you want to get the docs of Description: not playable of the last hour you can use the operators $ and, $ eq and $ gte .
$ gte es > = you can also use $ gt which is >
db.operations.find(
{$and: [
{ "Description": { $eq:"Not playable" } },
{ fecha: { $gte: "La fecha" } }
] }
)
maybe the query is not ordered exactly because I do not know how to handle the date but those operators should help you if or if