0

I have the following collections in my DB:

>db.event.find();
{ "_id" : ObjectId("5885eebeee7bce0b889976f0"), "_class" : "com.test.model.Ev
ent", "name" : "Event", "place" : "Berlin", "date" : ISODate("2017-03-01T23:00:00Z"), "speeches" : [ ], "attendees" : [ ], "links" : [ ] }

I want to create a mongoexport statement that exports to a csv only documents with particular date ISODate("2017-03-01T23:00:00Z")

I currently have the following command:

mongoexport --db event --collection event --query '{date{$gte:ISODate("2017-03-01T23:00:00Z")}}' --type=csv --fields _id,attendees,date --out "c:\myfile.csv"

But I get an error. The error message looks like this:

2017-01-23T15:46:35.033+0100 error validating settings:

query '[39 123 100 97 116 101 58 123 36 103 116 101 58 73 83 79 68 97 116 101 40 50 48 49 54 45 48 54 45 48 53 84 49 53 58 49 52 58 50 50 46 49 54 51 90 41 125 125 39]' is not valid JSON:

json: cannot unmarshal string into Go value of type map[string]interface {}

What's that about? Please help me:(

Mary Fel
  • 129
  • 1
  • 7
  • Try this `mongoexport --db event --collection event --query '{date:{$gte:ISODate("2017-03-01T23:00:00Z")}}' --type=csv --fields _id,attendees,date --out "c:\myfile.csv"` – s7vr Jan 23 '17 at 16:15
  • I tried this and I got the same error – Mary Fel Jan 23 '17 at 16:52
  • Have you tried swapping the single and double quotes: `mongoexport --db event --collection event --query "{'date':{'$gte':ISODate('2017-03-01T23:00:00Z')}}" --type=csv --fields _id,attendees,date --out "c:\myfile.csv"`? – chridam Jan 23 '17 at 19:25
  • Thank you, Chridam!It Works!!! – Mary Fel Jan 24 '17 at 19:49
  • 1
    @MaryFel: are you *sure* the query worked as you expected? `ISODate` is invalid extended JSON for `mongoexport` and you need to [use `$date` instead](https://stackoverflow.com/questions/36319052/use-mongoexport-with-a-query-for-isodate/36322337#36322337). – Dan Dascalescu Mar 02 '20 at 19:00

0 Answers0