GithubHelp home page GithubHelp logo

mongoose-taggable's Introduction

#mongoose-taggable

A simple tagging plugin for Mongoose

Adds the ability to add and remove tags to a document, and find models filtered by tags. Uses safe atomic updates to avoid race conditions.

NOTE: Indexes are not applied to the tags path, because you should probably use a compound index with other paths in your schema

##API

###model.addTag(tag) Add a tag (in memory only)

  • @param {String} tag The tag to add

  • @return {Boolean} False if tag already existed; true if added

###model.addTag(tag, cb) Add a tag to a document atomically

NOTE: This method modifies the document on the database

  • @param {String} tag The tag to add
  • @param {Function} cb Callback(err, addedTag) addedTag will be false if tag already existed; true if added

###model.removeTag(tag) Remove a tag (in memory only)

  • @param {String} tag The tag to add

  • @return {Boolean} False if tag didn't exist; true if removed

###model.removeTag(tag, cb) Remove a tag from a document atomically

NOTE: This method modifies the document on the database

  • @param {String} tag The tag to remove
  • @param {Function} cb Callback(err, removedTag) removedTag will be false if tag didn't exist; true if removed

###model.hasTag(tag) Returns whether the document as a given tag

  • @param {String} tag

  • @return {Boolean}

###Model.filterByTags(query, includeTags, [excludeTags]) Alters a query to filter by tags.

  • @param {Query} query Mongoose query object
  • @param {String[]} includeTags Tags the document must have (must have all)
  • @param {String[]} excludeTags Tags the document must NOT have (must not have any)

##Changelog ###v0.5.0

  • Changed the way excludeTags works in filterByTags(), from an AND operation to an OR operation. The method now selects items that have ALL of the includeTags but filters out items that have ANY of the excludeTags.

mongoose-taggable's People

Contributors

powmedia avatar

Watchers

 avatar  avatar

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.