簡體   English   中英

查詢mongodb 3.6集合以獲取最近24小時內創建的文檔

[英]query mongodb 3.6 collection for document created in the last 24 hours

查詢mongodb 3.6集合以獲取最近24小時內在php中創建的文檔。

集合

{
    "_id" : ObjectId("5a85b8d7a7c1cb1f380000a6"),
    "userid" : "matt",
    "post" : "the value of human life",
    "message" : [ ],
    "imgsrc" : "/images/pic.jpg",
    "state" : "lagos",
    "repost" : [ ],
    "updated" : "2018-02-15 17:44:07",
    "created" : "2018-02-15 17:44:07"
}

使用mongodb聚合,

use MongoDB;
$this->connection = new MongoDB\Client("mongodb://localhost:27017");
private $dbname = 'database';
private $db;
private $collection;
$this->db = $this->connection->{$this->dbname};
$this->collection = $this->db->collection;


$date = Date("Y-m-d H:i:s", strtotime("-24 hours"));
$pipeline = array(
['$match' =>[
    ['created' =>['$gt'=> $this->timedate->setDate($date)]]
]                
]);
$query = $this->collection->aggregate($pipeline);
return $query->toArray();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM