laravelmongodbjenssegers-mongodb

Get data based on time Mongo DB (Laravel)


array:4 [▼
  "_id" => ObjectId {#1108 ▶}
  "Date" => UTCDateTime {#1112 ▼
    +"milliseconds": "1591399800000"
  }
  "token" => "1013875"
  "value" => "78.65"
]

Hi, The sample object is as above, I need to get data(collection) where the Date is equal to 1591399800000(Time in milliseconds). Db is Mongo DB, Laravel framework.

DB::table('table_name')->where('Date','1591399800000')->first();

not giving me the required output.


Solution

  • I have done like this and getting required results:

    $start_time = new \DateTime('-5 minutes');
    
    $end_time=new \DateTime('-4 minutes');
    
    DB::table('table_name') 
       ->where('Date',array('$gte' => $start_time,'$lte' => $end_time)) 
       ->first()