Tom6106181
Posts: 0
Joined: Fri Aug 02, 2013 12:39 pm

Search for items in collection based on time

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

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

Search for items in collection based on time

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

Tom6106181
Posts: 0
Joined: Fri Aug 02, 2013 12:39 pm

Search for items in collection based on time

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

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

Search for items in collection based on time

preDate()/pre should start from upper case.

Tom6106181
Posts: 0
Joined: Fri Aug 02, 2013 12:39 pm

Search for items in collection based on time

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

Return to “Issues”