MongoExport error - cannot unmarshal string

荒凉一梦 提交于 2019-12-12 01:36:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!