Find objects between two dates MongoDB

后端 未结 14 1973
余生分开走
余生分开走 2020-11-21 06:03

I\'ve been playing around storing tweets inside mongodb, each object looks like this:

{
\"_id\" : ObjectId(\"4c02c58de500fe1be1000005\"),
\"contributors\" :          


        
相关标签:
14条回答
  • 2020-11-21 06:29

    Using with Moment.js and Comparison Query Operators

      var today = moment().startOf('day');
      // "2018-12-05T00:00:00.00
      var tomorrow = moment(today).endOf('day');
      // ("2018-12-05T23:59:59.999
    
      Example.find(
      {
        // find in today
        created: { '$gte': today, '$lte': tomorrow }
        // Or greater than 5 days
        // created: { $lt: moment().add(-5, 'days') },
      }), function (err, docs) { ... });
    
    0 讨论(0)
  • 2020-11-21 06:29

    Why not convert the string to an integer of the form YYYYMMDDHHMMSS? Each increment of time would then create a larger integer, and you can filter on the integers instead of worrying about converting to ISO time.

    0 讨论(0)
提交回复
热议问题