我正在尝试使用Mongo作为数据库,PHP作为语言来建立一个简单的博客系统。我不确定如何将日期或时间戳放入Mongo中(我猜我需要一个时间戳,以便能够按照它们发布的降序将文章取回)。下面是我现在写的草稿,它创建了一个PHP日期并将其插入其中,但似乎它以字符串形式呈现。在Oracle中我已经习惯了处理这个问题,但是在Mongo中这让我感到惊讶。有什么建议吗?
try{
date_default_timezone_set('America/New_York');
//$dt = date('j-m-y h-i-s');
$conn = new Mongo(); // connect
$db = $conn->selectDB("blog");
$collection = $db->items;
$item =array(
'title' => $_POST['title'],
'txt' => $_POST['txt'],
'labels' => $_POST['labels'],
'user' => $_POST['user'],
'dt' => date('j-m-y h-i-s')
);
$collection->insert($item);
/// disconnect from server
$conn->close();
} catch ( MongoConnectionException $e ) {
echo '<p>Couldn\'t connect to mongodb, is the "mongo" process running?</p>';
exit();
}