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 🙏

© 2024 – Pkg Stats / Ryan Hefner

mongoose-text-search

v0.0.2

Published

MongoDB 2.4 text search support for mongoose

Downloads

675

Readme

#mongoose-text-search

Provides MongoDB 2.4 text search support for mongoose.

Build Status

Example:

// modules
var mongoose = require('mongoose');
var textSearch = require('mongoose-text-search');

// create our schema
var gameSchema = mongoose.Schema({
    name: String
  , tags: [String]
  , likes: Number
  , created: Date
});

// give our schema text search capabilities
gameSchema.plugin(textSearch);

// add a text index to the tags array
gameSchema.index({ tags: 'text' });

// test it out
var Game = mongoose.model('Game', gameSchema);

Game.create({ name: 'Super Mario 64', tags: ['nintendo', 'mario', '3d'] }, function (err) {
  if (err) return handleError(err);

  Game.textSearch('3d', function (err, output) {
    if (err) return handleError(err);

    var inspect = require('util').inspect;
    console.log(inspect(output, { depth: null }));

    // { queryDebugString: '3d||||||',
    //   language: 'english',
    //   results:
    //    [ { score: 1,
    //        obj:
    //         { name: 'Super Mario 64',
    //           _id: 5150993001900a0000000001,
    //           __v: 0,
    //           tags: [ 'nintendo', 'mario', '3d' ] } } ],
    //   stats:
    //    { nscanned: 1,
    //      nscannedObjects: 0,
    //      n: 1,
    //      nfound: 1,
    //      timeMicros: 77 },
    //   ok: 1 }
  });
});

Output:

The output is not limited to the found documents themselves but also the complete details of the executed command.

The results property of the output is an array of objects containing the found document and its corresponding search ranking. score is the ranking, obj is the mongoose document.

For more information about these properties, read the MongoDB documentation.

Options

mongoose-text-search supports passing an options object as the second argument.

Example:

var options = {
    project: '-created' // do not include the `created` property
  , filter: { likes: { $gt: 1000000 }}
  , limit: 10
  , language: 'spanish'
}

Game.textSearch('game -mario', options, callback);

Notes:

As of mongoose 3.6.0, text indexes must be added using the Schema.index() method.

As of MongoDB 2.4.0, text search is experimental/beta. As such, this functionality is not in mongoose core.