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 🙏

© 2025 – Pkg Stats / Ryan Hefner

mongotagger

v1.1.1

Published

Tagging and Document relationship plugin for Mongoose

Downloads

22

Readme

#mongoTagger

Basic tagging and article relationship plugin for Mongoose

Please use mongoTagger 1.1.1

Creates methods to add, remove, and display tags to and for a document. As well as find models filtered by tags, and provide documents with strong relationship to original.

Note: This plugin is meant to be associated with a schema like "Articles", or "Documents", however, for full functionality, a Tag Schema must also be created and passed in as an option when the plugin is added.

##Getting Started First you'll need to npm install the plugin

$ npm install --save mongotagger

Next you'll need to require the module in your models.

mongoTagger = require("mongoTagger");

After you've created your document Schema add the plugin to it like so:

ArticleSchema.plugin(mongoTagger, Tag);

Note: that the "Tag" argument passed must be a Tags Model that has the keys "articleId" and "name".

Something like this:

var TagSchema = new Schema({
name: String,
articleId: String,
})

var Tag = mongoose.model('Tag', TagSchema);
module.exports = Tag

That's pretty much it!

##API Note: Code Examples below will use "article" as the document name and "Article" will refer to the parent model.

###model.addTag(tag, cb) Add a tag to a document, both as a nested array and as an Article_Tag_Association Hash.

article.addTag('Caz!!', function (err, tag){
if(err){
	console.log(err);
}else{
 	console.log(tag);
    }
});

The first parameter passed must be a String.

NOTE: This method modifies the database

###model.removeTag(tag) Removes a tag from a document and from the Article_Tag_Association Hash

article.removeTag('Filo!!')

The parameter passed must be a String.

NOTE: This method modifies the database

###model.displayTags(cb) Returns all of the tags associated with the document that calls it. Takes only a call back as an argument.

article.displayTags(function (err, tags){
if(err){
	console.log(err);
}else{
 	console.log(tags);
    }
});

###Model.tagFilter(includes, cb) Filters the Entire collection of documents for those with a tag or tags. The first parameter takes an Array of Strings and returns the documents which have at least one of the tags in the Array.

Article.tagFilter(function (err, docs){
if(err){
	console.log(err);
}else{
 	console.log(docs);
    }
}); 

Note: This is a Static and not an document method.

###model.relations([includes], cb) Returns Documents that are related to the document that calls it, by tags. The paramater "includes", is optional, takes an array of Strings, and returns documents related through the tags in Includes.

article.relations([includes], function (err, docs){
if(err){
	console.log(err);
}else{
 	console.log(docs);
    }
}); 

If only a call back is passed, this method will return all documents associated with the document that calls it with a "Relationship Score" associated with each. Each Documents tags will be cross referenced to the calling documents tags and the more in common, the higher the score.

###model.keywords(includes, field, cb) Returns documents that are related to the calling document by keywords. The parameter "Includes", must be an Array that contains a String, however the string can include multiple words. The parameter, "field", must be an Array that contains the Name of the Schema field to be queried, as a String.

Note: The fields to be queried must be indexed as "text". For Example to query the fullArticle field, the Schema might look like this

fullArticle: {type: [String], index: "text"}

The keyword method could then be called like this:

 article.keywords(includes, field, function (err, docs){
if(err){
	console.log(err);
}else{
 	console.log(docs);
    }
});

Note: This method does not allow for calling common english words like, "the", "to", or "a".

###Inner Keywords The Keyword method is set up to run on a document because of it's "inner keyword" functionality. When called the Method can accept the "inner keywords" as a string. When this is passed, the entire text of the associated field of an article is checked against other docs creating a more robust relationship. Along with a relationship score the Inner Keyword Method will return the words that are in common between two texts with a count of how many times the word has appeared.

For Example, this Database Call:

article.keywords( ["inner keywords"], ['full'], function (err, docs){
		if(err){
			console.log(err);
		}else{
			console.log(docs[0].commonWords);
		}
	})  

Would yeild something like this:

[ { full: [ 'The series whose second season began airing last week depicts the gloveless hands of surgeons aggressively exploring all three of these daunting body cavities. It’s this bloody medical realism, set to a minimalist score ...' ],
  tags: [ 'filo!!' ],
  __v: 1,
  source: 'Sun',
  author: 'C.W. Gaffney',
  title: 'Concateny',
  _id: 562fbe73e762c0ceaf2d6a28 },
{ score: 5 },
commonWords: { began: 1, hands: 1, medical: 2} ] 

##ToDos

  • ~~Add a key-word-search relations method that will provide a prioritized list of documents based on key words in the text.~~

  • ~~Add a count for each common word when using the Keyword Method.~~

  • Add sort for common words.

  • refactor relations method so larger database searches use only the join table and then populate the selected documents.

  • Normalize text input.