1

I am working on sails js with mongodb with sails-mongo adapter , My problem is i cant fetch the result between two dates using sails-mongo.

So is there any solution for retrieve this data, actually i want to get total count of each day day's entries (Last 15 days).

So please share if you know anything or any alternative way to come out from this problem.

-- Thanks - ND

Nishchit
  • 18,284
  • 12
  • 54
  • 81

1 Answers1

5

Simply use condition in single object in WHERE or FIND or COUNT

.where({ "createdAt" : { ">" : new Date(start), "<" : new Date(end) }})

.find({ "createdAt" : { ">" : new Date(start), "<" : new Date(end) }})

.count({ "createdAt" : { ">" : new Date(start), "<" : new Date(end) }})

See This example

    var start = moment('12-06-2014').startOf('day');
    var end = moment('12-06-2014').endOf('day');

    User.find().where({ "createdAt" : { ">" : new Date(start), "<" : new Date(end) }})
            .exec(function (err, user) {

                if (err)
                    return res.json(Res.toJson(false, err, 'Error'))

                return res.json(Res.toJson(true, user, 'User'))
            });
Nishchit
  • 18,284
  • 12
  • 54
  • 81
  • Thanks for answering you question, Also, can you help with mine located here? [sails error messages](http://stackoverflow.com/questions/29443791/sails-mongo-adapter-normalize-error-messages) . Thanks! – hussainb Apr 04 '15 at 07:40