Question

trying to use mongoexport to export a csv of the oplog... tried all quote combinations I have read so far...

../mongodb/bin/mongoexport --csv -d local -c oplog.rs -o export.csv -f {op,ns,o._id} -q "{ts: { \"$gte\": Timestamp(1355100998000,1)} , op :{ \"$nin\" : [\"c\",\"n\"]}"

but I keep getting

ERROR: too many positional options
.....

what could be wrong?

After a lot of screwing around I have tried this

q="{op: { \$nin: [\"c\",\"n\"]}}"
mongoexport --csv -d local -c oplog.rs -o export.csv -f {op,ns,o._id} -q "$q"

and this works like a charm. but still this

q="{ts: { \$gte: Timestamp(1355100998000,1)}, op: { \$nin: [\"c\",\"n\"]}}"
../mongodb/bin/mongoexport --csv --db local --collection oplog.rs -o changelog.csv --fields op,ns -q "$q"

does not work. Output

 Assertion: 10340:Failure parsing JSON string near: ts: { $gte

Feel something is wrong with Timestamp()?

Was it helpful?

Solution

So finally this is how it should be done... or how I did it. It is pretty fast tried it on 30000 records takes max 2 seconds. All thats happening is that I am storing the results in a new collection by using mongo with --eval option

q="db.oplog.rs.find({ ts : { \$gte : Timestamp( $timestamp, 1)}, op : { \$nin : [\"c\",\"n\"] } }, { op : 1 , ns : 1 , \"o._id\" : 1 , h : 1 } ).forEach(function(x){db.changelog.save(x);})"

../mongodb/bin/mongo localhost:27017/local --eval "$q"

and then export it as .csv using mongoexport

../mongodb/bin/mongoexport --csv --db local --collection changelog -o changelog.csv --fields "o._id","op","ns","h"

and removinf the temporary database to support future changelogs

../mongodb/bin/mongo localhost:27017/local --eval 'db.changelog.remove()'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top