Mongodb mongoexport排除文档
我有一个MongoDB集合,其中包含以下文档。有些文档有1个字段,有些文档有2个字段。我感兴趣的是将只有两个字段的文件导出为CSV文件。我可以使用什么查询来排除具有1个字段的查询Mongodb mongoexport排除文档,mongodb,csv,mongodb-query,mongoexport,Mongodb,Csv,Mongodb Query,Mongoexport,我有一个MongoDB集合,其中包含以下文档。有些文档有1个字段,有些文档有2个字段。我感兴趣的是将只有两个字段的文件导出为CSV文件。我可以使用什么查询来排除具有1个字段的查询 [ { "id" : 1, }, { "id" : 2, }, { "id" : 3 "productId": 300 } ] 我的mongoexport命令是:mongoexport--username x--password x--host x--db mydb--collecti
[
{
"id" : 1,
},
{
"id" : 2,
},
{
"id" : 3
"productId": 300
}
]
我的mongoexport命令是:
mongoexport--username x--password x--host x--db mydb--collection mycl--type=csv--fields id,productid--out“c:\myfile.csv”
在我添加查询的地方尝试一下这个命令
mongoexport --username x --password x --host x --db mydb --collection mycol --type=csv --fields id,productid --query '{ "$and": [ { "id": {"$exists":true}},{"productId":{"$exists":true}}] }' --out "c:\myfile.csv"
也可能是这样
mongoexport --username x --password x --host x --db mydb --collection mycol --type=csv --fields id,productid --query '{ "id": {"$exists":true},"productId":{"$exists":true} }' --out "c:\myfile.csv"
请参阅和Suresh,我尝试了这两种方法,但出现了错误“json:无法将字符串解组到map[string]接口{}类型的Go值中”在查询字段中使用双引号,如{“id”:{“$exists”:true},“productId”:{“$exists”:true}}。Suresh,您使用双引号的建议确实有效。