The only illegal characters in key names are "." and the first
character may not be "$". This is documented on the "Legal Key Names"
page:
http://www.mongodb.org/display/DOCS/Legal+Key+Names
Replacing the dot with a valid character is an acceptable solution.
Alternatively, you could rearrange your document structure, such that
each document contains two Keys; "filename", and "Binary_Data". I
believe that this is similar to your second proposed solution. In
general, it is more common for documents to contain the same keys.
This makes querying a little more straightforward.
For example, given the two following document structures:
{_id:1, "filename":"path/to/myFile", "Binary_Data":"100100..."}
{_id:2, "path/to/myFile" : "100100..."}
The first document (_id:1) would seem a little easier to write queries
for if the name of the file is known:
> db.files.find({"filename":"path/to/myFile"}
For the second document, the binary data would have to be known, or
another field would have to be matched on. Alternatively, the
"$exists" operator could be used.
> db.files.find({"path/to/myFile":{$exists:true}})
The $exists operator is explained here:
http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24exists
To me, the first document structure seems a little more
straightforward. Furthermore, an index may be created on the
"filename" key. Index creation is not really possible for the second
document, because each will have a different key name.
The most generic advice is to try it both ways, and experimentally
determine which method is best for your application.