mongotiles is a tilelive backend plug-in for MongoDB GridFS

npm install mongotiles
4 downloads in the last week
8 downloads in the last month


mongotiles is a tilelive.js backend (source/sink) plug-in for MongoDB GridFS

Q: What the heck does that mean?

A: With this installed, you can use MongoDBs built-in GridFS file store to read/write map image tiles from/to other tilelive.js sources/sinks (mbtiles, Mapnik, TileJSON, S3, etc.)

Q: Come again?

A: You can use MongoDB to serve maps (via an HTTP front-end to GridFS)

Q: Why would one want to do that?

A: Everybody loves MongoDB, Right?

Q: Where do the maps come from?

A: That's a really big question. Many days of poking around may be required to fully grok what you are asking here.

Places to start:


You need node.js. Then:

 npm install mongotiles

Nice! Now what?


Obviously, this works with (and depends upon) tilelive.js and MongoDB.

For example: Let's say you already have map tiles rendered with TileMill sitting in a .mbtiles file, and using something like TileStream to serve tiles alongside an application server isn't doing it for you. And you also happen to have an up-to-date MongoDB server running locally.

You should be able to easily copy all of your data from the .mbtiles file to your local MongoDB instance by setting up these other things:

 npm install tilelive
 npm install mbtiles

And then:

 ./node_modules/tilelive/bin/copy -s pyramid --minzoom=10 --maxzoom=18  "mbtiles:///Users/user/maps/Columbus.mbtiles" "mongotiles://"

The copy command above is a sample application provided by tilelive.js, and it has a bunch more options that you should check out. Tilelive is actually an API that any other app can use, so mongotiles should enable MongoDB to play nicely with apps and other data sources/sinks that also support tilelive. The source and sink URIs have custom protocols (mbtiles: and mongotiles:) that tilelive knows what to do with via the backend plugins you've now installed.

Serving your tiles out of MongoDB over HTTP requires one more piece: an HTTP server that can use GridFS as its filestore (there are many options). In this example, mongotiles will use the default fs GridFS bucket in the columbus_tiles database, so you'll need to configure your HTTP server to look there for GridFS files.

Once that's up-and-running, if you point a Leaflet enabled web page page to e.g.{z}_{x}_{y} and you'll be serving up map tiles from MongoDB (the URL path before tile_{z}_{x}_{y} will depend on how you configure the HTTP server).

For what it's worth, this also lets you serve up the TileJSON information for your maps, just use, e.g.

Note: if you wish to use a GridFS "bucket" other than the default ("fs"), then simply append that bucket name to the end of the mongotiles: URI you use with tilelive, for example:

npm loves you