mongo-fuse is a virtual file system which represents MongoDB collections as
folders, and documents as editable json files. This allows you to use regular
unix toolchain for working with mongodb. For example, you can edit mongo docs
with vim
or emacs
(or even sed
, nano
or libreoffice
), search
docs with grep
, navigate databases with either your favourite shell, or
something like mc
or ranger
.
This project was written for fun during a 24-hours hackathon in July 2012.
Checkout sources, then in the project folder run:
$ pip install .
or, if you don't have pip
installed:
$ easy_install .
You might need root privilegies if you don't use virtualenv (though it's much better to start using virtualenv).
To start having fun with mongo-fuse
, we need to mount virtual folder that
will be representing mongo server:
$ mkdir -p /tmp/fusetest
$ mongofuse /tmp/fusetest
By default, your local mongodb instance (localhost:27017) will be mounted.
To change this, pass optional --db
argument.
That' it! Now we can navigate to the mounted folder. Top level subfolders are mongo databases:
$ cd /tmp/fusetest
$ ls
blog dbhasha genericData pcat week5
classify dbhashb loadserverscripts status test-classify
clientAdmin etlpy-stats local students test-etlpy-titan
curationTool etlpy-status test
Under database, you'll find folders for collections:
$ ls pcat
products products_bak system.indexes
Finally, each collection folder contains number of json files, one file per doc:
$ ls pcat/products
507d95d5719dbef170f15bf9.json 507d95d5719dbef170f15bfc.json 507d95d5719dbef170f15bff.json
507d95d5719dbef170f15bfa.json 507d95d5719dbef170f15bfd.json 507d95d5719dbef170f15c00.json
507d95d5719dbef170f15bfb.json 507d95d5719dbef170f15bfe.json 507d95d5719dbef170f15c01.json
Each file is a plain text/json file, which can be viewed, edited, copied (and even deleted) just as any other normal text file:
$ head pcat/products/507d95d5719dbef170f15bf9.json
{
"_id": {
"$oid": "507d95d5719dbef170f15bf9"
},
"for": [
"ac3",
"ac7",
"ac9"
],
"name": "AC3 Series Charger",
$ grep AC3 pcat/products/*
pcat/products/507d95d5719dbef170f15bf9.json: "name": "AC3 Series Charger",
pcat/products/507d95d5719dbef170f15bfa.json: "name": "AC3 Case Green",
pcat/products/507d95d5719dbef170f15bfc.json: "name": "AC3 Case Black",
pcat/products/507d95d5719dbef170f15bfd.json: "name": "AC3 Case Red",
Collection can have thousands documents in it, and it would not be cool to see
all of those. That's why mongofuse
shows only few dozens of docs, but
allows you to filter results by creating virtual folders. Here is how it works:
$ cd pcat/products
$ mkdir -p by_name/AC3
$ ls ./by_name/AC3
TODO: finish docs