I have a collection "companies". Every object in this collection has "lastcall"-param. It's a simple string, containing UNIX time of the last call. I'd like to find all the companies, where lastcall is higher than a AND lower than b. How can I do this? Here's the code I use to access to compnaies:
//query to lastcall
collection.find( {'lastcall': a} , function (err, companies) {
companies.each(function (err, company) {
//do something with every object...
});
});
This code will return all the companies where 'lastcall' = A, but I need all the ones where A < 'lastcall' < B. How can I do this? Thanks!
There is an example in the docs for Advanced Queries that's exactly what you want:
db.collection.find({ "field" : { $gt: value1, $lt: value2 } } ); // value1 < field < value
...Conditional operators <, <=, >, >= and != can't be used directly, as the query object format doesn't support it but the same can be achieved with their aliases $lt, $lte, $gt, $gte and $ne. When a field value needs to match a conditional, the value must be wrapped into a separate object.
{"fieldname":{$gte:100}}