mongodb系统当前日期(yyyy-mm-dd)

时间:2018-07-26 10:37:41

标签: mongodb sysdate

我只想从当天的集合中提取MONGODB中的数据。 我已经尝试过此请求:

su    
# mount -o rw,remount /
# mount -o rw,remount /system
# mount -o rw,remount /system/xbin

但我收到该消息错误:

db.hello.aggregate([
    { $match: { "name": "btb" } },
    { $where: function() { 
        today = new Date(); 
        today.setHours(0,0,0,0);
        return (this.date.getTimestamp() >= today)
    }},
    { $group: {
        _id: { articles: "$articles" },
        total: { $sum: 1 }
    }},
    { $project: {
        "articles": 1,
        "total": 1
    }},
    { $sort: { "total":-1 } }
]) 

2 个答案:

答案 0 :(得分:1)

尝试

db.collection.find({ createdAt: { $lte: new Date() , $gte: new Date(ISODate().getTime() - 1000 * 60 * 18)} })`

18分钟前(从现在开始)

答案 1 :(得分:0)

我通常会这样获取数据:

db.mycollection.find(
 { "createdAt" : 
  {
   "$gte" : new Date("2013-10-01T00:00:00Z"),
   "$lt" : new Date("2013-10-02T00:00:00Z") }
 })

$gte更大 $lt的花费少于