Access Mongo documents in a FUSE filesystem
This filesystem exposes mongo's structure, features and constrainst.
This is meant to ease the administration of a mongo database, it is NOT a general-purpose filesystem that uses Mongo for storage (look for GridFS if you want this)
# pip install mongofs
If you run into any problems, you may need to install fuse-python from your distributions repositories:
# apt-get install python-fuse
# mount mongodb://localhost ~/mongo -t mongofs
The filesystem is structured as /database/collection/field_name/field_value.json
If the field value is not unique, multiple field names/values pairs are stacked together: /database/collection/field1/value1/field2/value2/.../fieldN/valueN.json
. This is equivalente to the mongo query {"field1":value1, "field2":value2, ..., "fieldN":valueN}
.
Note values are JSON strings. Therefore, if your field type is a string, you will need to quote it. E.g., /db/collection/name/"John Smith".json
. (Yes, it is a bit cumbersome)
$ mkdir ~/mongo/new_db #Create a database
$ rmdir ~/mongo/old_db #Remove a database
$ mv ~/mongo/old_db_name ~/mongo/new_db_name #Rename a database
$ mkdir ~/mongo/db/new_collection #Create a database
$ rmdir ~/mongo/db/old_collection #Remove a database
$ mv ~/mongo/db/old_collection_name ~/mongo/db/new_collection_name #Rename a database
$ cat ~/mongo/example_db/example_collection/foo/\"bar\".json
{
"_id": {
"$oid": "56297a874971f41c1b6e151b"
},
"foo": "bar",
"baz": 56,
"abc": {
"a": "A",
"b": "B",
"c": "C"
}
}
$ echo '{"a":"b"}' > ~/mongo/example_db/example_collection/_id/56.json
$ cat ~/mongo/example_db/example_collection/_id/56.json
{
"_id": 56,
"a": "b"
}
$ rm ~/mongo/example_db/example_collection/_id/56.json
Sometimes a human needs to be view or edit a Mongo document. And when humans are involved, a good UI helps a lot!
I have been using Robomongo for that. It is a fine UI, but it doesn't compare with being able to use my favorite $EDITOR
.
When I realized I was copy-pasting between robomongo and my text editor all the time, I decided It was time to fix that!
- Read/Write documents using Mongo's Query Syntax
- Support for renaming filters and files