python - pymongo date field converted to unknown date format -


i getting data 1 collection using python , processing , storing in collection. in processed collection of date fields looks different date(-61833715200000).

i use below code data , processing , bulk insert values new collection.

fleet_managers = taximongo.users.aggregate([{ "$match": { "role" : "fleet_manager"}}]) fleet_managers = pd.dataframe(list(fleet_managers)) fleet_managers['city_id'] = fleet_managers['region_id'].map({'57ff2e84f39e0f0444000004':'chennai','57ff2e08f39e0f0444000003':'hyderabad'}) pros_fleet_managers.insert_many(fleet_managers.to_dict('records')) 

the collection looks this:

{     "_id" : objectid("58006678ee5e0e29c5000009"),     "deleted_at" : nan,     "region_id" : "57ff2e84f39e0f0444000004",     "reset_password_sent_at" : date(-61833715200000),     "current_sign_in_at" : isodate("2016-10-14t06:07:55.568z"),     "last_sign_in_at" : isodate("2016-10-14t06:07:45.574z"),     "remember_created_at" : date(-61833715200000)         } 

what did wrong here. already.

i have found solution using $ifnull while projecting fields.

fleet_managers = taximongo.users.aggregate([{ "$match": { "role" : "fleet_manager"}},{"$project":{'_id':1,'deleted_at':{ "$ifnull": [ "$deleted_at", "null" ] },  'reset_password_sent_at':{ "$ifnull": [ "$reset_password_sent_at", "null" ] },                                  'region_id':1,'current_sign_in_at':1,'last_sign_in_at':1,'remember_created_at':{ "$ifnull": [ "$remember_created_at", "null" ] }}}]) fleet_managers = pd.dataframe(list(fleet_managers)) fleet_managers['city_id'] = fleet_managers['region_id'].map({'57ff2e84f39e0f0444000004':'chennai','57ff2e08f39e0f0444000003':'hyderabad'}) pros_fleet_managers.insert_many(fleet_managers.to_dict('records')) 

the above code gives solution need handle null or non existence dynamically i.e., when fetching source collection.

help me out on this.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -