2016-04-01 22 views
0

Aşağıdaki belgelerle birlikte bir MongoDB koleksiyonum var. Belgelerin bir kısmı 1 alana sahiptir ve bazıları 2'dir. Sadece bir CSV dosyasına 2 alanlı olanları ihraç etmek istiyorum. 1 alanı olanları hariç tutmak için hangi sorguyu kullanabilirim?mongoexport belgeleri dışta tut

[ 
{ 
    "id" : 1, 
}, 

{ 
    "id" : 2, 
}, 

{ 
    "id" : 3 
    "productId": 300 
} 
] 

benim mongoexport komut: mongoexport --username x --password x --host x --db mydb --collection mycol --type=csv --fields id,productid --out "c:\myfile.csv"

+0

See [ '--query olarak (https://docs.mongodb.org/manual/reference/program/mongoexport/#cmdoption--query) ve ['$ varolanlar '] (https://docs.mongodb.org/manual/refer ence/operator/query/exists /) –

cevap

-1

i sorgu

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" 

ekledik bu bir deneyin bu böyle olabilir böyle

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" 
+0

Suresh, Ben her iki yöntemi de denedim ve hatayı alıyorum "json: tür haritasının Git değerine dizgesiz dizesi olamaz [string] interface {}" – degmo

+0

{gibi sorgu alanlarında çift tırnak kullanın. { "id": {"$ var": true}, "productId": {"$ var": true}} –

+0

Suresh, hala çalışmadı. – degmo