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

mongodb system current date (yyyy-mm-dd)

我只想从集合中提取 MONGODB 中当天的数据。 我试过这个请求:

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 } }
]) 

但我收到错误消息:

####################################################################

Unable to execute the selected commands

Mongo Server error (MongoCommandException): Command failed with error 16436: 'Unrecognized pipeline stage name: '$where'' on server localhost:27017. 

The full response is:
{ 
    "ok" : 0.0, 
    "errmsg" : "Unrecognized pipeline stage name: '$where'", 
    "code" : NumberInt(16436)
}

####################################################################

我通常这样获取数据:

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

$gte 大于 $lt 不到

试试这个

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

18 分钟前(从现在开始)