Hi,
I managed to hack the src of import.cpp (into custom_import.cpp; this
was from mongo 1.6.5 source) to allow arbitrary user defined
separators and it works pretty good. Not checked this for performance
etc but my source data goes into mongo just fine...
mongocustom_import -h localhost:27017 -u admin -p XXXXXX --dbpath /
var/lib/mongo -d myDB -c PreIndex -f "collist1-n" --type osv --drop --
stopOnError --zsep '~~' --file /pathto/PreIndex.out.utf8
Fri Dec 31 14:26:35 [tools] CMD: drop myDB.PreIndex
OSV type with separator ~~
Fri Dec 31 14:26:35 [tools] building new index on { _id: 1 } for
myDB.PreIndex
Fri Dec 31 14:26:35 [tools] done for 0 records 0.008secs
...
imported 6319145 objects
Fri Dec 31 14:28:34 dbexit:
Fri Dec 31 14:28:34 [tools] shutdown: going to close listening
sockets...
Fri Dec 31 14:28:34 [tools] shutdown: going to flush oplog...
Fri Dec 31 14:28:34 [tools] shutdown: going to close sockets...
Fri Dec 31 14:28:34 [tools] shutdown: waiting for fs preallocator...
Fri Dec 31 14:28:34 [tools] shutdown: closing all files...
Fri Dec 31 14:28:35 closeAllFiles() finished
Fri Dec 31 14:28:35 [tools] shutdown: removing fs lock...
Fri Dec 31 14:28:35 dbexit: really exiting now
Fri Dec 31 14:28:35 PST 2010: Finished
Approx rate of import => 53100 r/s
For those interested, copy
http://onepwr.dyndns.org/code/custom_import.cpp
as custom_import.cpp into mongodb-src-r1.6.5/tools/. Also modify
SConstruct to have:
normalTools = [ "dump" , "restore" , "export" , "import" , "files" ,
"stat" , "custom_import" ]
Then "scons all" will build mongocustom_import.cpp in root folder.
Strip it and use as needed. I guess I could get rid of a lot of
unnecessary stuff in here as this program does'nt need to be as
"flexible" as mongoimport.
I was also wondering if anyone could point me to do a batch/
bulk_insert using the C++ driver? I realized that mongoimport also
does a single insert at a time.
Srinivas.