Page 1 of 1
Help with _updatedAt query
Posted: Sun Mar 22, 2015 11:58 pm
by Kal
Hi,
I am having a hard time figuring this out... how do I enter a "where" clause for checking if the "_updatedAt" field is within the last hour? In other words, I want to retrieve a record only if it was updated within the last 60 minutes.
Just to clarify, I want to do this within the MongoDB itself (as a query criterion), not bring down all the records and then check which of them were updated within 60 minutes.
Thanks,
-Kal.
Help with _updatedAt query
Posted: Mon Mar 23, 2015 3:37 pm
by Kal
Hi, any help with this, please?
Thanks!
Help with _updatedAt query
Posted: Tue Mar 24, 2015 9:52 pm
by Egor Kotov6832188
Kal,
1) on where parameter click JS button
2) inside opened editor add:
return '{"_updatedAt":"2014-12-18 19:56:13.003"}';
Unfortunately, we can't provide all date calculations
Help with _updatedAt query
Posted: Tue Mar 24, 2015 10:01 pm
by Kal
Sorry, Egor, that did not answer the question asked, which is to figure out a way to get things in a time interval, not at a particular time. I know how to do this already.
Help with _updatedAt query
Posted: Fri Mar 27, 2015 12:59 am
by Yurii Orishchuk
Hi Kal,
Here is a solution to get previously modified(in 60 minutes) items:
click "list/query" service "before mapping".
find "where" request parameter.
click "JS" on this request parameter.
populate it with following JS code:
pre
var now = new Date();
var hourBefore = new Date(now.getTime() - 60 * 60 * 1000);
var d1 = hourBefore.toISOString();
var whereObject = {
"_updatedAt": {
$gt: {
"$date": d1
}
}
};
return JSON.stringify(whereObject);
/pre
Regards.
Help with _updatedAt query
Posted: Fri Mar 27, 2015 4:41 am
by Kal
Thanks, Yurii! I need to do this on the server side, but I think the same technique should work. I will give that a shot.
Help with _updatedAt query
Posted: Sat Apr 04, 2015 1:05 am
by Kal
Works like a charm, thanks.