[SERVER-5543] mongoimport should support ISODate() format for import Created: 09/Apr/12  Updated: 15/Aug/12  Resolved: 09/Apr/12

Status: Closed
Project: Core Server
Component/s: Tools
Affects Version/s: 2.1.0
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Alvin Richards (Inactive) Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-5675 mongoimport should support all (exten... Closed
Participants:

 Description   

Problem:
mongoimport does not support JSON with the ISODate representation, for example

{ "_id" : ObjectId("4e5bb37258200ed9aabc5d67"), "name" : "Bob", "age" : 28, "address" : "123 fake street", "ts" : ISODate("2010-09-28T13:07:12Z") }

It will fail with the following error

Mon Apr 9 09:06:09 Assertion: 10340:Failure parsing JSON string near: , "ts" : I

Solution:
Extend monogimport to support ISODate

Test case:

> db.foo.save(

{name:"bob", ts: ISODate("2012-04-09")}

);

> db.foo.find(

{name:"bob"}

);

{ "_id" : ObjectId("4f82992047a6783d6427f207"), "name" : "bob", "ts" : ISODate("2012-04-09T00:00:00Z") }

> exit

cut & paste that object into a file , e.g. tmp/3/json

$ mongoimport -d test -c foo /tmp/3.json



 Comments   
Comment by Scott Hernandez (Inactive) [ 21/Apr/12 ]

I created the general issue here ; SERVER-5675

So all extended formats and outputs by the shell are supported. Please feel free to vote that issue up.

Comment by Scott Hernandez (Inactive) [ 21/Apr/12 ]

Dave, that is not json, it is just something the shell can interpret, since it is an object definition/function. The shell is more than a json parser. The printjson function is unfortunately named since really it is not json, in the standard meaning. You can also see the "extended" json format here for a better understanding : http://www.mongodb.org/display/DOCS/Mongo+Extended+JSON

Comment by Dave Elliot [ 21/Apr/12 ]

But if you use a mongo command like this:

db.mycollection.find().forEach(printjson);

It renders the date fields using ISODate, like:

"fromDate" : ISODate("2012-04-19T19:30:00Z")

So it's printing JSON in a format that you can't import?

Comment by Scott Hernandez (Inactive) [ 09/Apr/12 ]

This is the incorrect format for both ObjectId and ISODate in a json file, and not the format from mongoexport.

Your example should look like this:

{ "_id" : { "$oid" : "4f82d374156eab1311b3a9ab" }, "ts" : { "$date" : 1333973876058 } }

Generated at Thu Feb 08 03:09:13 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.