Reputation: 2418
According to this, it's not possible to save datetime.date
instances in MongoDB using Python and pymongo. It says in the FAQ that it's an unsupported type and to use datetime.datetime
instead.
However, it's listed (as #9) in the BSON data types page here, so is this just out-of-date, or is there a reason I can't use python this data type?
Upvotes: 3
Views: 5893
Reputation: 2881
From mongo docs: http://docs.mongodb.org/manual/reference/bson-types/#document-bson-type-date
The official BSON specification refers to the BSON Date type as the UTC datetime.
So, there is while it is written as "Date", it's still a datetime in BSON
. If you want just date
, you can set the hours/minutes/seconds/ms to 0
.
Also, as specified on the docs about timestamp
:
*NOTE
The BSON timestamp type is for internal MongoDB use. For most cases, in application development, you will want to use the BSON date type. See Date for more information.*
The difference between datetime
and timestamp
is: datetime is an abstraction of date (day, month, year) and time (hour, min, second), and timestamp is the number of seconds since epoch.
Upvotes: 3