sonu kumar
sonu kumar

Reputation: 47

import mongodb database to mongolab

i have export mongoDB from local Database and it's in following format and save as CSV file.

_id,accomodation,state,user
ObjectId(565dae266dbda6964f061d99),No,California,ObjectId(5651fb48b0dfa73c134df161)

Then i try to run mongoimport with following command

 mongoimport -h hostname -d dbname -c collectionname -u username
 -p password --file filename.csv --type csv --headerline

import success but Mongolab store DB in strict mode as i read so they store

ObjectId(565dae266dbda6964f061d99)  in this format 
"_id": {
        "$oid": "565dae266dbda6964f061d99"
    }

But the Data i imported it just store as ObjectId(565dae266dbda6964f061d99)...i want to know how i can import that save in safe mode it my all the ObjectID data store in "$oid": "565dae266dbda6964f061d99" format in my mongolabDb.

Let me know if you have any question..

Thanks.

Upvotes: 1

Views: 317

Answers (1)

Alex
Alex

Reputation: 38529

As you correctly note in your question, MongoLab uses Strict MongoDB Extended JSON so Object IDs are represented like that:

{ "$oid": "<id>" }

There's no way of changing this on the hosted service.

Upvotes: 1

Related Questions