mongoose-plugin-tags
A mongoose.js plugin to automatically generate tags from a document path.
Note: tagging updates occur when document is saved.
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
Param | Type | Default | Description |
---|
[options] | object | | |
options.path | string | "tags" | the path to create the propterty for storing tags. |
options.optionKey | string | "tags" | the path options key to mark paths for inclusion in tagging. |
options.options | object | | property options to set (type will always be an Array of String ). (e.g. {select: false}) |
options.match | string | "/[##][a-z_0-9]+/g" | the regular expression to match tags. |
options.map | string | "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
},
bar: {type: String}
});
schema.plugin(tagsPlugin);
var Foo = mongoose.model('Foo', schema);
var foo = Foo();
foo.foo = 'I just leanered what a hashtag is #BehindTheTimes';
foo.save();
With Mulitple Fields
var tagsPlugin = require('mongoose-plugin-tags');
var schema = Schema({
foo: {
type: String,
tags: true
},
bar: {
type: String,
tags: true
}
});
schema.plugin(tagsPlugin);
var Foo = mongoose.model('Foo', schema);
var foo = Foo();
foo.foo = 'You know what grinds my gears? #rant';
foo.bar = '#People #who #use #hashtags #like #this';
foo.save();
License
Apache 2.0