[SERVER-1244] mongoimport converts string _id's to ObjectIDs when importing from a json file Created: 16/Jun/10  Updated: 29/May/12  Resolved: 28/Jun/10

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

Type: Bug Priority: Major - P3
Reporter: Jerry Cheung Assignee: Mathias Stearn
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

6/15 nightly, gentoo


Operating System: ALL
Participants:

 Description   

I have a json export file created from mongoimport 1.4.3 which has id's in the string format:

{ "_id": "1234abcd", ... }

When I try to import this file, mongoimport 1.5.x will convert all the IDs to ObjectIDs. If I export the imported collection, I get:

{ "_id":

{ "$oid": "1234abcd"}

, ...}

The 1.4.x behavior is to keep the id's as strings if the json file's id's are strings.



 Comments   
Comment by Mathias Stearn [ 28/Jun/10 ]

no, the only type of _id that mongo will create is an ObjectID

Comment by Jerry Cheung [ 28/Jun/10 ]

I made a mistake when I reported the bug. The file I was importing had a mix of documents with string id's, or no id's. For docs that had no id's, mongo created the record with an ObjectID. Docs with string id's are imported correctly with string ids. Is there a way to force mongo to use string IDs on import?

Comment by Mathias Stearn [ 25/Jun/10 ]

I just tried this with both 1.4.3 and 1.5.git and they both leave it as a string. could you upload an example file that shows different behavior?

Generated at Thu Feb 08 02:56:29 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.