Start a new topic
Answered

How to use lessThanOrEqualTo in Business Logic?

Hello 

I'm running against a wall using lessThanOrEqualTo in Business Logic. I came up to the point that it probably won't work that way (as it does in Javascript API): 

var checkDate = 201907241500

logger.info("step 1");

modules.collectionAccess.collection('products').lessThanOrEqualTo(('release.unlockdate', checkDate), function (err, docs) {
   if (err) {
     logger.error('Query failed: '+ err);
  } else {
    logger.info ('durch');
  }
});

  It outputs "step 1" and no further error message.


This f.e. works fine but this is only an equal operation:   

var checkDate = 201907241500;
modules.collectionAccess.collection('products').find({"release.unlockdate": checkDate}, function (err, publish) {
logger.info(JSON.stringify(publish));
});

 I'm looking for the query function that allows me to search for records with a value equal or less than a given value. Is that possible?


The samples you provided in the documentation are all simple. I couldn't find examples with advanced query logic.


Regards

   





Best Answer

Hello Tayger,


Please check the following code snippet which shows how to use "Less Than or Equal to" operator:


function onRequest(request, response, modules) {
  var logger = modules.logger;
  
  modules.collectionAccess.collection('Book').find({"startDate": {"$lte": "2018-11-02T11:29:44.211Z"}}, function (err, docs) {
  if (err) {
    logger.error('Query failed: '+ err);
  } else {
    logger.info('Found records are ' + JSON.stringify(docs));
    logger.info('Number of records is ' + docs.length);
    response.body = docs;
    response.complete(200);
  }
});
  
}




Thanks,

Pranav

Kinvey


Answer

Hello Tayger,


Please check the following code snippet which shows how to use "Less Than or Equal to" operator:


function onRequest(request, response, modules) {
  var logger = modules.logger;
  
  modules.collectionAccess.collection('Book').find({"startDate": {"$lte": "2018-11-02T11:29:44.211Z"}}, function (err, docs) {
  if (err) {
    logger.error('Query failed: '+ err);
  } else {
    logger.info('Found records are ' + JSON.stringify(docs));
    logger.info('Number of records is ' + docs.length);
    response.body = docs;
    response.complete(200);
  }
});
  
}




Thanks,

Pranav

Kinvey

Wow, this is it, thank you Pranav! It works like a charm! Next time I will consider the MongoDB documentation that exactly reflects that.


Regards

Tay

Agreed..It works too good...Thank you so much for the solution 

Login or Signup to post a comment