PHP MongoDate changed to ISODate, why?

3,174 views
Skip to first unread message

RJ

unread,
Oct 3, 2011, 5:24:37 PM10/3/11
to mongodb-user, R...@monthsof.me
Hello,

I recently updated a library that uses PHP's MongoDate to store all
date related fields.

After running the library I noticed MongoDate objects were no longer
being stored. Instead an ISOdate object is stored.

Any idea's what I "accidentally" did to trigger the change?

Thanks

Flavio Percoco

unread,
Oct 3, 2011, 5:30:26 PM10/3/11
to mongod...@googlegroups.com, R...@monthsof.me
Hi,

MongoDate[0] representes date objects for the database which are ISODates[1].

[0] http://www.php.net/manual/en/class.mongodate.php
[1] http://www.mongodb.org/display/DOCS/Data+Types+and+Conventions

Cheers



RJ
3 de octubre de 2011 23:24

RJ Johnston

unread,
Oct 3, 2011, 6:18:11 PM10/3/11
to Flavio Percoco, mongod...@googlegroups.com
Flavio,

Thank you for responding although I don't think this answers my question.

Let me clarify; previously date objects were stored as MongoDate (sec => 1235, usec => 1235).

Now they are stored like ISOdate("yyyy-dd-mm").  

I do not know what I did to trigger this alternative save method.  Maybe the right question is "what do you have to pass a new MongoDate(xxx) object to return an ISOdate() object?

I should be able to reverse eng from there and correct.

Thanks

Sent from my iPhone

On Oct 3, 2011, at 5:30 PM, Flavio Percoco <flap...@gmail.com> wrote:

Hi,

MongoDate[0] representes date objects for the database which are ISODates[1].

[0] http://www.php.net/manual/en/class.mongodate.php
[1] http://www.mongodb.org/display/DOCS/Data+Types+and+Conventions

Cheers



<compose-unknown-contact.jpg>
RJ
3 de octubre de 2011 23:24

Kristina Chodorow

unread,
Oct 4, 2011, 10:02:01 AM10/4/11
to mongodb-user
MongoDB has a "date" type. In PHP, this is deserialized to a
MongoDate. In the mongo shell, this is deserialized to ISODate. If
you're seeing ISODates in the shell, that is normal and how dates
should look in the shell. Are you seeing ISODate in PHP? If so, can
you paste a var_dump of the document?



On Oct 3, 6:18 pm, RJ Johnston <rj.johns...@monthsof.me> wrote:
> Flavio,
>
> Thank you for responding although I don't think this answers my question.
>
> Let me clarify; previously date objects were stored as MongoDate (sec =>
> 1235, usec => 1235).
>
> Now they are stored like ISOdate("yyyy-dd-mm").
>
> I do not know what I did to trigger this alternative save method.  Maybe the
> right question is "what do you have to pass a new MongoDate(xxx) object to
> return an ISOdate() object?
>
> I should be able to reverse eng from there and correct.
>
> Thanks
>
> Sent from my iPhone
>
> On Oct 3, 2011, at 5:30 PM, Flavio Percoco <flape...@gmail.com> wrote:
>
> Hi,
>
> MongoDate[0] representes date objects for the database which are
> ISODates[1].
>
> [0]http://www.php.net/manual/en/class.mongodate.php
> [1]http://www.mongodb.org/display/DOCS/Data+Types+and+Conventions
>
> Cheers
>
>  ------------------------------
>
>  <compose-unknown-contact.jpg>RJ <rjdjohns...@gmail.com>

RJ Johnston

unread,
Oct 4, 2011, 3:42:45 PM10/4/11
to Flavio Percoco, mongod...@googlegroups.com
No thoughts?  

I noticed another anomaly, all the "/" symbols are now escaped!  (http:\/\/someurl.com).  Cannot figure this out either.  Maybe related? 



Sent from my iPhone

On Oct 3, 2011, at 5:30 PM, Flavio Percoco <flap...@gmail.com> wrote:

Hi,

MongoDate[0] representes date objects for the database which are ISODates[1].

[0] http://www.php.net/manual/en/class.mongodate.php
[1] http://www.mongodb.org/display/DOCS/Data+Types+and+Conventions

Cheers



<compose-unknown-contact.jpg>
RJ
3 de octubre de 2011 23:24

Sam Millman

unread,
Oct 4, 2011, 3:59:56 PM10/4/11
to mongod...@googlegroups.com
ISO date is tz compliant, notice the format of the time when looking at it in shell.

escaping is normal for BSON (think of JSON) arrays. Slashs is always a bit of a problem.

How exactly are they being stored in your DB?

--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.

Sam Millman

unread,
Oct 4, 2011, 4:02:03 PM10/4/11
to mongod...@googlegroups.com
What I was meant to say on the end of that is that so long as they do not come out of your PHP script escaped everyhting is fine.

If they do then there is something afoot that we need to get to the root of.

Sam Millman

unread,
Oct 4, 2011, 4:07:56 PM10/4/11
to mongod...@googlegroups.com
Also ISODate is international format:

http://www.w3.org/QA/Tips/iso-date

Basically it is better than the old date object

Sam Millman

unread,
Oct 4, 2011, 4:14:57 PM10/4/11
to mongod...@googlegroups.com
Ha!

I only just noticed the original question:


"Any idea's what I "accidentally" did to trigger the change?"

Answer: You upgraded.

The old date() object is dead. You need not do anything different it will just make the date storing in the DB better.

RJ

unread,
Oct 4, 2011, 10:27:08 PM10/4/11
to mongodb-user
Brilliant!  Thanks Sam

On Oct 4, 4:14 pm, Sam Millman <sam.mill...@gmail.com> wrote:
> Ha!
>
> I only just noticed the original question:
>
> "Any idea's what I "accidentally" did to trigger the change?"
>
> Answer: You upgraded.
>
> The old date() object is dead. You need not do anything different it will
> just make the date storing in the DB better.
>
> On 4 October 2011 21:07, Sam Millman <sam.mill...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Also ISODate is international format:
>
> >http://www.w3.org/QA/Tips/iso-date
>
> > Basically it is better than the old date object
>
> > On 4 October 2011 21:02, Sam Millman <sam.mill...@gmail.com> wrote:
>
> >> What I was meant to say on the end of that is that so long as they do not
> >> come out of your PHP script escaped everyhting is fine.
>
> >> If they do then there is something afoot that we need to get to the root
> >> of.
>
> >> On 4 October 2011 20:59, Sam Millman <sam.mill...@gmail.com> wrote:
>
> >>> ISO date is tz compliant, notice the format of the time when looking at
> >>> it in shell.
>
> >>> escaping is normal for BSON (think of JSON) arrays. Slashs is always a
> >>> bit of a problem.
>
> >>> How exactly are they being stored in your DB?
>
> >>> On 4 October 2011 20:42, RJ Johnston <rj.johns...@monthsof.me> wrote:
>
> >>>> No thoughts?
>
> >>>> I noticed another anomaly, all the "/" symbols are now escaped!
> >>>>  (http:\/\/someurl.com).  Cannot figure this out either.  Maybe
> >>>> related?
>
> >>>> Sent from my iPhone
>
> >>>> On Oct 3, 2011, at 5:30 PM, Flavio Percoco <flape...@gmail.com> wrote:
>
> >>>>  Hi,
>
> >>>> MongoDate[0] representes date objects for the database which are
> >>>> ISODates[1].
>
> >>>> [0] <http://www.php.net/manual/en/class.mongodate.php>
> >>>>http://www.php.net/manual/en/class.mongodate.php
> >>>> [1] <http://www.mongodb.org/display/DOCS/Data+Types+and+Conventions>
> >>>>http://www.mongodb.org/display/DOCS/Data+Types+and+Conventions
>
> >>>> Cheers
>
> >>>>  ------------------------------
>
> >>>>  <compose-unknown-contact.jpg>RJ <rjdjohns...@gmail.com>

Sam Millman

unread,
Sep 16, 2012, 7:20:10 PM9/16/12
to mongod...@googlegroups.com, KevOu
Forwarding back down to mongodb-user. Poster accidently posted directly to me.

On 17 September 2012 00:19, Sam Millman <sam.m...@gmail.com> wrote:
PHP Driver comes bundled with MongoDate: http://php.net/manual/en/class.mongodate.php

You can use it like:

$db->insert(array('ts' => new MongoDate()));

Adding a time() arg to the class call will set the date to that time.


On 16 September 2012 23:44, KevOu <kevin....@gmail.com> wrote:
Sam,

Sorry I don't know if my previous message went through...
Would you know the best way to "prepare" a php date to upload to mongo
db ISODate format ?
You said date() object is dead so which one do you suggest to use ?

Thanks for your kind help,
> >>>>http://www.mongodb.org/display/DOCS/Data+Types+and+Conventions
>
> >>>> Cheers
>
> >>>>  ------------------------------
>
> >>>>  <compose-unknown-contact.jpg>RJ <rjdjohns...@gmail.com>

Kevin Childs

unread,
Sep 17, 2012, 3:07:37 AM9/17/12
to mongod...@googlegroups.com
I saw that, but MongoDate constructor doesn't manage TZ although ISODate does :-)

Kev

Sam Millman

unread,
Sep 17, 2012, 3:22:48 AM9/17/12
to mongod...@googlegroups.com
Yea MongoDate can take a tz, it will default it down to Z time with a + notation for the tz but you must set the PHP timezone to be that tz in order for it to work.


Kevin Childs

unread,
Sep 17, 2012, 3:41:29 AM9/17/12
to mongod...@googlegroups.com
Aaaaahhhh ok ill try :-) thx

Kev
Reply all
Reply to author
Forward
0 new messages