[SERVER-14253] mongoexport generates 'ObjectID', while the shell is using 'ObjectId' Created: 14/Jun/14  Updated: 25/Apr/16  Resolved: 26/Jun/14

Status: Closed
Project: Core Server
Component/s: Tools
Affects Version/s: 2.6.1
Fix Version/s: 2.7.3

Type: Improvement Priority: Minor - P4
Reporter: Daniel Coupal Assignee: Matt Kangas
Resolution: Done Votes: 0
Labels: community-team
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Backwards Compatibility: Minor Change
Sprint: Server 2.7.3
Participants:

 Description   

A customer reports that it is not very convenient for mongoexport --csv to output ObjectID as a type, while it is not a valid string in the Mongo shell, which accepts ObjectId.

[ec2-user@host]$ mongoexport --db app --collection data -q '{"date.v": {$lt : new Date(1)}}' --csv --fields '_id' -o -
_id
ObjectID(518d83ba89a92bb3057252eb)
ObjectID(525b23207ca1bb3f0c001eac)
ObjectID(525b23207ca1bb3f0c001ea4)
ObjectID(525b23207ca1bb3f0c001e8c)
ObjectID(525b23207ca1bb3f0c001e94)
ObjectID(525b23207ca1bb3f0c001e9c)
ObjectID(525b23207ca1bb3f0c001eb4)
ObjectID(525b23207ca1bb3f0c001e84)
 
mongos> db.app.coveredassets.find({_id: new ObjectID("518d83ba89a92bb3057252eb")}).pretty()
2014-06-13T19:52:04.561+0000 ReferenceError: ObjectID is not defined
 
mongos> db.app.coveredassets.find({_id: new ObjectId("518d83ba89a92bb3057252eb")}).pretty()
{
"_id" : ObjectId("518d83ba89a92bb3057252eb"),
...
}



 Comments   
Comment by Matt Kangas [ 26/Jun/14 ]

mongoexport --csv now renders ObjectId values as follows:

ObjectId('53ab7f413c69c0ab304e16aa')

Note the use of single quotes. This was necessary to have a result that is both valid to paste into the mongo shell and still conform with RFC-4180 quoting rules for CSV.

Note also that mongoimport --type csv does not import these values as ObjectIds, either before or with this change. They are imported as strings.

Comment by Githook User [ 26/Jun/14 ]

Author:

{u'username': u'kangas', u'name': u'Matt Kangas', u'email': u'matt.kangas@mongodb.com'}

Message: SERVER-14253 mongoexport csv should generate 'ObjectId', not 'ObjectID'
Branch: master
https://github.com/mongodb/mongo/commit/5632cbd52558daeecaf42270a7e919418cb53ab0

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