0

I am fetching data according to date filter using node.js.

i have values stored in db as "February 12th 2016, 2:02:47 am"

When i am running find command

accounts.find({date:{$gte:'February 11th 2016, 59:59:59'}}).toArray(
        function(e, res) {
            if (e) callback(e)
            else callback(null, res)
        });

it returns the exact data i want. but when i runs the command

accounts.find({date:{$gte:'January 1st 2000, 59:59:59'}}).toArray(
        function(e, res) {
            if (e) callback(e)
            else callback(null, res)
        });

it returns nothing.

Please help me.

Thanks for your valuable time.

5
  • 1
    Have you stored date as string literals ? You would never get the desired results, if you treat date as a string.
    – BatScream
    Feb 13, 2016 at 7:27
  • as far as I know. (hope if I am wrong others can correct me).you will have to loop through each document and convert (if in shell) to date using the js new Date(). else it is just another string to mongodb. You can of course do that on the application level as well.
    – ibininja
    Feb 13, 2016 at 8:22
  • better yet use ISODate(),
    – ibininja
    Feb 13, 2016 at 8:23
  • Thanks guy's you helped me a lot :)
    – Prem Tomar
    Feb 13, 2016 at 8:26
  • Follow answers from this question to get an idea of how you can convert the string formatted dates into date objects.
    – chridam
    Feb 13, 2016 at 9:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.