Laravel-mongodb: Issue in saving date as ISODate in mongoDB using laravel

Created on 1 Nov 2016  路  3Comments  路  Source: jenssegers/laravel-mongodb

date is not getting saved as ISODate in mongodb, though looking at users table I can see the timestamp dates are being saved in correct format. But for some reason when I try to save date it gets save in the below format:

"date_departure" : {
"date" : "2016-07-14 17:50:17.000000",
"timezone_type" : 3,
"timezone" : "UTC"
}

which actually should be in a format like "date_departure" : ISODate("2016-07-13T06:43:12.998Z")

Pls suggest a fix!

Most helpful comment

Assumption collection name is _Event_ .
use Event->save() not Event::insert($array) .
Also add line "protected $dates = ['created_at', 'updated_at', 'datetime']" on model file

All 3 comments

i changed my data, move date to root document and add this line on my model file "protected $dates = ['created_at', 'updated_at', 'datetime']" and then try to update all document and move date from child doc. to root but its not working when you use eloquent update method, then i delete document and create again with root datetime field. its worked for me.

Assumption collection name is _Event_ .
use Event->save() not Event::insert($array) .
Also add line "protected $dates = ['created_at', 'updated_at', 'datetime']" on model file

use_this_value = new \MongoDB\BSON\UTCDateTime($datetime_object);

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Idnan picture Idnan  路  3Comments

lgt picture lgt  路  3Comments

tomartailored picture tomartailored  路  3Comments

viacheslavpleshkov picture viacheslavpleshkov  路  3Comments

sanjay1688 picture sanjay1688  路  3Comments