Page 1 of 1

Search for items in collection based on time

Posted: Sat Feb 08, 2014 12:56 pm
by Tom6106181

Hi. I am working on a search function for my app, everything working just fine, if I insert the today date manually in mapping.

However, I have a problem, I want to tell the search function to only retrieve items where "START" is in the future from current date.

How can I do this in mapping? Insert "now.date" to the "where" query.

This is what I have so far:
code//need the today date to only retrieve items with start in the future. this is not working..
var today = new date();
//console.log(new date());
return '{"name":{"$regex":".' + value + '.", "$options":"i"}, "start" : {"$gt" :"2014-03-06 00:00:00.000"}}';/code


Search for items in collection based on time

Posted: Sat Feb 08, 2014 1:15 pm
by Igor

Hi,

Date must be in ISO DateTime format:
pre
2014-03-06T00:00:00.000Z
/pre
Please try this code
pre
code
var today = new Date();
var isodate = today.toISOString();
/code
/pre


Search for items in collection based on time

Posted: Sat Feb 08, 2014 1:18 pm
by Tom6106181

yes but when used in mapping, it throws me an error in console.
codeReferenceError date is not defined /code


Search for items in collection based on time

Posted: Sat Feb 08, 2014 1:21 pm
by Igor

preDate()/pre should start from upper case.


Search for items in collection based on time

Posted: Sat Feb 08, 2014 1:23 pm
by Tom6106181

hahahaha... thanks :p Sometimes, youre head is not in the game..
Could not figure out why it would not work..
Perhaps time for a break ;p