1.2.2 • Published 10 years ago

mongoose-plugin-tags v1.2.2

Weekly downloads
1
License
Apache 2.0
Repository
github
Last release
10 years ago

mongoose-plugin-tags

Codeship Status for CentralPing/mongoose-plugin-tags Code Climate for CentralPing/mongoose-plugin-tags Dependency Status for CentralPing/mongoose-plugin-tags

A mongoose.js plugin to automatically generate tags from a document path.

Note: tagging updates occur when document is saved.

Installation

npm i --save mongoose-plugin-tags

API Reference

Example

var tagsPlugin = require('mongoose-plugin-tags');
var schema = Schema({...});
schema.plugin(tagsPlugin[, OPTIONS]);

mongoose-plugin-tags~options

Kind: inner property of mongoose-plugin-tags

ParamTypeDefaultDescription
optionsobject
options.pathstring"tags"the path to create the propterty for storing tags.
options.optionKeystring"tags"the path options key to mark paths for inclusion in tagging.
options.optionsobjectproperty options to set (type will always be an Array of String). (e.g. {select: false})
options.matchstring"/##+/g"the regular expression to match tags.
options.mapstring"function"the function to strip tag indicators (e.g. '#'). Defaults to stripping the first character from a tag.

Examples

With A Single Field

var tagsPlugin = require('mongoose-plugin-tags');
var schema = Schema({
  foo: {
    type: String,
    tags: true // indicates that foo should be included in tagging
  },
  bar: {type: String} // will not be included
});
schema.plugin(tagsPlugin);

var Foo = mongoose.model('Foo', schema);
var foo = Foo(); // foo.tags --> []
foo.foo = 'I just leanered what a hashtag is #BehindTheTimes'; // foo.tags --> []
foo.save(); // foo.tags --> ['BehindTheTimes']

With Mulitple Fields

var tagsPlugin = require('mongoose-plugin-tags');
var schema = Schema({
  foo: {
    type: String,
    tags: true // indicates that foo should be included in tagging
  },
  bar: {
    type: String,
    tags: true // indicates that bar should be included in tagging
  }
});
schema.plugin(tagsPlugin);

var Foo = mongoose.model('Foo', schema);
var foo = Foo(); // foo.tags --> []
foo.foo = 'You know what grinds my gears? #rant'; // foo.tags --> []
foo.bar = '#People #who #use #hashtags #like #this'; // foo.tags --> []
foo.save(); // foo.tags --> ['rant', 'people', 'who', 'use', 'hashtags', 'like', 'this']

License

Apache 2.0