gentrobot
gentrobot

Reputation: 671

mongofiles get_id not working from cmd on Windows 7

I am trying to get a file from GridFS using mongofiles command. The command works perfectly on my Mac Terminal but the same command throws error on Windows cmd.

On OS X Terminal:

mongofiles --db newdb get_id 'ObjectId("58a2e2dee4b052100af93a4f")' --local 32.gif
2018-08-02T11:18:14.773+0530    connected to: localhost
finished writing to: 32.gif

On Windows CMD

mongofiles -d newdb get_id 'ObjectId("58a2e2dee4b052100af93a4f")' --local 32.gif
2018-08-02T11:20:15.049+0530    connected to: localhost
2018-08-02T11:20:15.050+0530    Failed: error opening GridFS file with _id 'ObjectId(58a2e2dee4b052100af93a4f)': not found

I have tried supplying various combinations of strings for the objectid, escaping and adding slashes, single and double quotes, but nothing worked. I am sure I am missing something simple, but I have spent more than an hour on this now.

EDIT The file with the _id does exist in the db on the windows mongo instance as well:

> use newdb
switched to db newdb
> db.fs.files.find({"_id":ObjectId("58a2e2dee4b052100af93a4f") });

{ "_id" : ObjectId("58a2e2dee4b052100af93a4f"), "chunkSize" : NumberLong(261120)
, "length" : NumberLong(3944), "md5" : "330af44d664364882237d92a5d7f29a8", "file
name" : "/AAA/BBB/CCC/32.gif", "contentType" : "/AAA/BBB/CCC/32.gif", "uploadDate" : ISODate("2017-02-14T10:58:38.447Z"), "a
liases" : null }

However, if I try to get the files using filename, I get another error about mongofiles trying to parse the filename as an argument. Enclosing the filename inside double quotes doesn't work as well

Upvotes: 2

Views: 1127

Answers (1)

gentrobot
gentrobot

Reputation: 671

As I had thought, it was a pretty simple solution. Guess I am a bit worked up to figure it out sooner. What worked for me was:

mongofiles -d newdb get_id "ObjectId(\"58a2e2dee4b052100af93a4f\")" --local 32.gif

Upvotes: 2

Related Questions