title: How to import Mongodb ObjectId from CSV file using mongoimport?
body: <p>I am struggling to import Mongodb's ObjectId from a CSV file using mongoimport:</p>
  
  <p>I tried every combination and escape method I could think of but can't import ObjectId correctly from CSV.</p>
  
  <p>First I tried importing exactly what I get exported from MongoDB to CSV. 
  I am using MongoDB 2.2.1.</p>
  
  <p>I just created two collections and referenced one document's _id in another document:</p>
  
  <pre><code>use yourdb
  db.createCollection("student")
  db.createCollection("class")
  db.student.insert({"name":"Peter"})
  db.student.find() returns { "_id" : ObjectId("5143af326d44e1ceb372121d"), "name" : "Peter" }
  db.class.insert({"student_id": ObjectId("5143af326d44e1ceb372121d"),"name":"II-4"})
  </code></pre>
  
  <p>Then I used mongoexport command in shell:</p>
  
  <pre><code>mongoexport -h localhost:3002 -d yourdb -c classes --csv -f student_id,name &gt; export.txt
  </code></pre>
  
  <p>Resulting CSV looks like this: </p>
  
  <pre><code>student_id,name
  ObjectID(5143af326d44e1ceb372121d),"II-4"
  </code></pre>
  
  <p>Then I imported the resulting CSV using:</p>
  
  <pre><code>mongoimport -h localhost:3002 -d yourdb -c class --type csv --file export.txt --headerline
  </code></pre>
  
  <p>Quering class collection now returns:</p>
  
  <pre><code>db.class.find()
  { "_id" : ObjectId("5143afc66d44e1ceb372121e"), "student_id" :   ObjectId("5143af326d44e1ceb372121d"), "name" : "II-4" }
  { "_id" : ObjectId("5143b44788df173ba096550e"), "student_id" : "ObjectID(5143af326d44e1ceb372121d)", "name" : "II-4" }
  </code></pre>
  
  <p>As you can notice student_id field in the second document is actually a string and not MongoDB ObjectId.</p>
  
  <p>I am wrong on something or Mongo can't import it's own exported CSV??</p>