0

I am trying to export a subset of documents that contain a specific ObjectId from a collection of Twitter searches. To do this, I am using the following script:

mongoexport --db twitter --collection tweets --csv --fieldFile CSVfields.txt --out .\tweets.csv --query query.txt

...where CSVfields.txt references the specific document keys that I want in the export and query.txt contains:

{ "search" : ObjectId("525f9cfdb3685db029000001") }

When I run this, I get an error saying:

assertion: 16619 code FailedToParse: FailedToParse: Expecting '{': offset:0

Any idea what I am doing wrong?

Thanks!

1 Answer 1

1

--query takes a JSON query, not a file.

So either of the following should work:

mongoexport --db twitter --collection tweets --csv --fieldFile CSVfields.txt --out .\tweets.csv --query `cat query.txt`

mongoexport --db twitter --collection tweets --csv --fieldFile CSVfields.txt --out .\tweets.csv --query '{ "search" : ObjectId("525f9cfdb3685db029000001") }'
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Daniel for the response. I had tried the second option but not the first. Both keep giving me this error which I seem to be getting with everything I try: "ERROR: too many positional options"
I figured it out. My console wasn't escaping the JSON argument. When I nested my quotations starting with " and then ', it did the trick. This syntax worked: mongoexport --db twitter --collection tweets --csv --fieldFile CSVfields.txt --out tweets.csv --query "{ search : ObjectId('52613e36b3685db029000004') }"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.