npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mongoose-fs

v0.2.7

Published

Mongoose plugin for large attributes storage in GridFS

Downloads

28

Readme

mongoose-fs

Mongoose plugin for large attributes storage in GridFS.

Why ?

A basic mongo document can only keep a limited number of information. This plugin gives you the power to skip this limit by storing the big and not queried parts into GridFS.

Installation

npm install mongoose-fs

or add it to your package.json.

Usage

Schema decoration

First you'll need to decorate your schema with the plugin.

Your GridFS keys shouldn't be in your schema and your schema should be in strict mode (default behavior). If you don't respect those two conditions, your keys will be stored in mongo and in GridFS at the same time.

You won't be able to run queries on those keys, so ensure that it's just for storing additional data in your model.

Here's an example :

var mongoose = require('mongoose');
var mongooseFS = require('mongoose-fs');

var fileSchema = mongoose.Schema({
  name: String,
  size: Number,
  creation_date: Date
});

fileSchema.plugin(mongooseFS, {keys: ['content', 'complement'], mongoose: mongoose});
var File = mongoose.model('File', fileSchema);

In this example, the content of the content and complement keys will be stored in GridFS.

Plugin options

For more control we provide those options to the plugin :

  • keys is mandatory. It's just an array of keys processed by the plugin.
  • mongoose is mandatory. Pass your mongoose module (Why ? because the internal mongoose's gridfs module should be absolutely the same....)
  • bucket is the GridFS in which you want to store this data. By default it will be 'fs'.
  • connection is your mongo connection. By default it uses the default mongoose connection.

Saving a document

Nothing has to be done here. The content of the keys will be automatically sent into GridFS.

Loading a document

When you get a document back from mongo, you'll still have to unpack it's gridfs content.

It remains very simple to use :

File.findById(id, function (err, file) {
  if(err) {
    return done(err);
  }
  file.retrieveBlobs(function (err) {
    if(err) {
      return done(err);
    }
    // Now everything is ready !
  });
});