问题
I have a MongoDB collection with the following documents. Some of the documents have 1 field and some have 2. I am interested in exporting only those that I have the field "productid". I am using the query below but getting the error: "cannot unmarshal string into GO value of type map[string] interface {}".
The document looks like this:
[
{
"id" : 1,
},
{
"id" : 2,
},
{
"id" : 3
"Product Info":
{
"ProductName" : "test"
}
}
]
The MognoExport command I am using is as follows: mongoexport --username x --password x --host x --db mydb --collection mycol --query '{"Product Info.ProductName":{"$exists":true}}' --type=csv --fields id,productid --out "c:\myfile.csv"
回答1:
I fixed this issue by updating my script to:
mongoexport --username x --password x --host x --db mydb --collection mycol --query "{ 'Product Info.ProductName':{$exists:true}}" --type=csv --fields id,productid --out "c:\myfile.csv"
来源:https://stackoverflow.com/questions/36435512/mongoexport-error-cannot-unmarshal-string