Mongoexport always give "invalid JSON" errors

1,919 views
Skip to first unread message

atoki...@gmail.com

unread,
Mar 31, 2015, 11:28:50 AM3/31/15
to mongod...@googlegroups.com
Hello,

I tried to export some documents from a specific collection and save it as an CSV file with the fieldnames in first line.
I use the command line and following code:

mongoexport --db DBNAME --collection collectionNAME --query
'{$text:{$search:"SEARCH-EXPRESSION"}}' --type=csv --fields
field1
,field2,field3,field4 --fieldFile file.csv

This throws everytime following error message:

error validating settings; query ''{$text:{$search:"SEARCH-EXPRESSION"}}'' is not valid JSON: json:cannot unmarshal string into Go value of type map[string]interface {}

How can I fix this?

Thank you very much in advance for your help and advice.

 

Will Berkeley

unread,
Mar 31, 2015, 12:23:21 PM3/31/15
to mongod...@googlegroups.com
I'm not having a problem with that command (minus --fieldFile, because --fields and --fieldFile aren't used together):

mongoexport --db test --collection test --query '{ $text : { $search : "SEARCH-EXPRESSION"} }' --type csv --fields field1,field2,field3,field4

What's your version of mongoexport (mongoexport --version)? I'm using 3.0.1.

-Will

atoki...@gmail.com

unread,
Apr 1, 2015, 3:15:22 AM4/1/15
to mongod...@googlegroups.com
Hi Will,
thank you for your answer.
I'm new to MongoDB and just read the documentation on its official website. And I thought that this "fieldFile" is needed to write the fieldnames in the first line of the CSV and needs to be defined in "fields". That seems to be a missunderstanding, thank you for the declaration. I use also 3.0.1. Is there something wrong with my JSON/BSON part? I want to search a substring inside a bigger string expression. Is this the right way for that?
Thank you very much for your advice.

atoki...@gmail.com

unread,
Apr 1, 2015, 4:47:06 AM4/1/15
to mongod...@googlegroups.com
Sorry, I didn't see that you improved my code. I tried your code now and I get following new error:

too many positional arguments: [$text : {  $search : SEARCH-EXPRESSION }  }' ]

If this code would work, it should get about 200000 records/documents. Is this too much?


 

Am Dienstag, 31. März 2015 18:23:21 UTC+2 schrieb Will Berkeley:
Reply all
Reply to author
Forward
0 new messages