如何在php mongo db中提取$ numberLong数据?

时间:2018-06-18 12:57:47

标签: mongodb mongodb-php php-mongodb

我将日期字段以ISO格式存储在像

这样的集合中
    {
      ...
      "startson": ISODate("2015-12-31T23:00:00.0Z"),
      "active" : 0
    }


    {
      ...
      "startson": ISODate("2017-12-31T23:00:00.0Z"),
      "active" : 1
    }

我必须提取日期字段并进行会话。

我试过像

       $_SESSION['activeAcademicyearStartsOn'] = $academicYear->startson

它存储为stdClass对象。如何直接获得$ numberLong值  并在会议中传递它?

实际代码就像

      if ($resultArray["result"] !== "empty") {
                foreach ($resultArray as $academicYear) {
                    if ($academicYear->active === 1) {
                        $_SESSION['activeAcademicyearId'] = $academicYear->_id->{'$oid'};
                        $_SESSION['activeAcademicyearStartsOn'] = $academicYear->startson->{'$time'}->{'$date'}->{'$numberLong'};
                }
              }
           }

当我们var_dump会话变量时,它包含像

这样的数据

object(stdClass)#11(1){[“$ date”] => object(stdClass)#12(1){[“$ numberLong”] => string(13)“1546297200000”}}

0 个答案:

没有答案