node package manager

Introducing npm Enterprise add-ons. Integrate third-party dev tools into npm…


gridfs with mongoose


Mongoose with GridFS.
GridFS is convenient way to store files and it allows all mongodb features like clusters and sharding. This library is intended to help GridFS usage with nodejs and mongoose. It allows efficient way to store data, e.g. on the fly gzipped before storing and when gzipped data is read back gzip can be extracted on the fly.

npm install gridfstore
  register schema
gridfstore.register('collection', myschema);
  store arguments:
  data                      -> string|buffer|readstream
  options: { gzip: true }   -> gzip input data before store gridfs
*/ metadata, data, [options,] callback)
/* mongoose model */
  read arguments:
  uuid                                    -> store generate uuid as filename
  options: { 
    gunzip: Boolean,                      -> gunzip output data before call callback (default: false)
    method: String   ('sync'|'async')     -> get as sync or asyncronously (stream)  (default: sync)
*/ uuid, [options,] callback)
var mongoose  = require('mongoose'),
   gridfstore = require('../lib/gridfstore');
var mymeta = {
  title: {type: String},
  owner: {type: String}
gridfstore.register('test', mymeta); {filename: 'test1.txt', title: 'example', owner: 'jva'}, 
                  'this is file content',
                  function(error, meta){
    //meta == whole metadata from gridfs