MongoExport错误-无法解组字符串 [英] MongoExport error - cannot unmarshal string

查看:116
本文介绍了MongoExport错误-无法解组字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含以下文档的MongoDB集合.有些文档有1个字段,有些则有2个.我只想导出那些我具有"productid"字段的文档.我正在使用下面的查询,但收到错误:无法将字符串解组为map [string]接口{}类型的GO值".

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 {}".

文档如下:

[
  {
     "id" : 1,
  },
  {
     "id" : 2,
  },
  {
     "id" : 3
     "Product Info":
      {
         "ProductName" : "test"
      }
  }
]

我正在使用的MognoExport命令如下: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"

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"

推荐答案

我通过将脚本更新为以下方式解决了此问题:

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"

这篇关于MongoExport错误-无法解组字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆