2016-04-01 8 views
0

Ich habe eine MongoDB-Sammlung mit den folgenden Dokumenten. Einige der Dokumente haben 1 Feld und manche 2. Ich möchte nur solche mit 2 Feldern in eine CSV-Datei exportieren. Welche Abfrage kann ich verwenden um solche mit 1 Feld auszuschließen?mongoexport Dokumente ausschließen

[ 
{ 
    "id" : 1, 
}, 

{ 
    "id" : 2, 
}, 

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

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

+0

See hinzugefügt haben [ '--query '] (https://docs.mongodb.org/manual/reference/program/mongoexport/#cmdoption--query) und [' $ exists'] (https://docs.mongodb.org/manual/refer enception/operator/query/exists /) –

Antwort

-1

versuchen diese, wo ich Abfrage

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" 

Oder es könnte sein wie

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, ich habe beide Methoden ausprobiert und erhalte den Fehler "json: kann String nicht entpacken in Go-Wert von Typmap [string] Schnittstelle {}" – degmo

+0

Verwenden Sie doppelte Anführungszeichen in Abfragefeldern wie { "id": {"$ exists": true}, "productId": {"$ existiert": true}} –

+0

Suresh, das hat immer noch nicht funktioniert. – degmo

Verwandte Themen