Kal
Posts: 0
Joined: Thu May 22, 2014 11:03 pm

Help with _updatedAt query

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.

Kal
Posts: 0
Joined: Thu May 22, 2014 11:03 pm

Help with _updatedAt query

Hi, any help with this, please?

Thanks!

Egor Kotov6832188
Posts: 0
Joined: Wed Nov 19, 2014 5:15 pm

Help with _updatedAt query

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

Kal
Posts: 0
Joined: Thu May 22, 2014 11:03 pm

Help with _updatedAt query

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.

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Help with _updatedAt query

Hi Kal,

Here is a solution to get previously modified(in 60 minutes) items:

  1. click "list/query" service "before mapping".

  2. find "where" request parameter.

  3. click "JS" on this request parameter.

  4. 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.

Kal
Posts: 0
Joined: Thu May 22, 2014 11:03 pm

Help with _updatedAt query

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.

Kal
Posts: 0
Joined: Thu May 22, 2014 11:03 pm

Help with _updatedAt query

Works like a charm, thanks.

Return to “Issues”