Coder Social home page Coder Social logo

mongoose-version2's Introduction

Mongoose Version

Mongoose Version is a mongoose plugin that automatically versions documents as they're modified. The previous versions are saved into a separate mongo collection.

!!!It disables the default mongoose3 versioning!!!

Installation

$ npm install mongoose-version2

Usage

To use mongoose-version for an existing mongoose schema you'll have to require and plugin mongoose-version into the existing schema.

The following schema definition defines a "Page" schema, and uses mongoose-version plugin with default options

var mongoose = require('mongoose'),
    Schema = mongoose.Schema,
    version = require('mongoose-version');

var Page = new Schema({
    title : { type : String, required : true},
    content : { type : String, required : true },
    path : { type : String, required : true},
    tags : [String],
});

Page.plugin(version, {});

Mongoose-version will define a schema that has all the same properties as Page plus a _refId field pointing to the original model.

Mongoose-version will add a static field VersionedModel to Page that can be used to access the versioned model of Page, for example for querying old versions of a document.

Option keys and defaults

  • versionProperty - the name of the property holding the version number
  • modelName - name of the mognoose model

Fork info

This is a based on https://github.com/saintedlama/mongoose-version.

Reasons for forking:

  • The original doesn't support multiple connections
  • The original is completely wroing as a mongoose plugin, as a schema can be instantiated as multiple models (multiple times) but the plugin doesn't support it.
  • Complex code for such a simple plugin
  • Strange work with the mongoose __v property
  • Unneeded mongoose requirement
  • Weird versioning action on document removal

mongoose-version2's People

Contributors

saintedlama avatar reggino avatar fghibellini avatar benjamta avatar doowb avatar

Watchers

Sander Houttekier avatar James Cloos avatar

Forkers

davduran

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.