samedi 18 février 2017

Meteor / MongoDB - How to write an if statement to check whether any item in array is greater than a specific value/date?

So, I have a function which should be executed in case that a if condition is true. I simply do not know how to implement it in a method. I have the following code:

Meteor.methods({
 'popItems': function () {
   var date = new Date().getTime();

    if ( "check if this.userId && any item in the array 'itemIds' is $gt date" ) {

     userManagement.update({
      '_id': this.userId
     },  {
         $pop: {'itemIds': -1}
         }
        } 
      );
    };
  }
});

So, in case the if condition is true, the $pop function should be executed. In case false, it should not. I wrote this for the if clause, but it doesn´t work:

if (this.userId && userManagement.find({
            'itemIds': {$gt: date}})) {...$pop function...}

Any help is highly appreciated! Thanks.

Aucun commentaire:

Enregistrer un commentaire