mongodb - mongoexport - export in ISO data format -


i trying export data mongodb date stored in iso format. eg -

    {     "_id" : "abcdef",     "log" : [         {             "ts" : isodate("2015-05-14t17:21:51z"),             "visitorid" : numberlong(219301285)         },         {             "ts" : isodate("2015-05-15t19:20:52z")         }     ],     "uts" : isodate("2015-05-14t17:21:50.589z") } 

when wrote export command

mongoexport --host localhost:27018 --db mydb --collection mycoll --query '{"log.ts":{$gte :new date(1431619200000)}}' --out test_1.json 

it give me results in json format, date format numeric

    {     "_id": "abcdef",     "log": [         {             "ts": {                 "$date": 1431624111000             },             "visitorid": 219301285         },         {             "ts": {                 "$date": 1431667764000             },             "visitorid": 0         }     ],     "uts": {         "$date": 1431624110589     } } 

what want date should in iso format , not numeric.

how can that?

i tried using below format, doesn't work , gives error

mongoexport --host localhost:27018 --db mydb --collection mycoll --query "{'log.ts':{'$gte' :{'$date':'2015-05-15 10:00:00.000z'}}}" --out test_1.json 

mongoexport produces strict mode json output. format, date represented { "$date": "<date>" } representation of <date> not homogeneous among mongodb versions:

  • starting mongodb 2.6 (to quote doc):
    " <date> iso-8601 date format mandatory time zone field following template yyyy-mm-ddthh:mm:ss.mmm<+/-offset>."
  • up mongodb 2.4, date represented "64-bit signed integer milliseconds since epoch utc (unsigned before version 1.9.1)."

if want "new" iso date representation directly mongoexport have update mongodb 2.6 @ least. otherwise have either:

  • to post-process data using favorite script language
  • or patch (backport?) change 2.6 2.4

none of them being long-term solution, of myself push toward updating mongodb (up >=3.0). understand it, may lead compatibility issues. ymmv.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -