Giter Club home page Giter Club logo

mongoose-keywords's Introduction

mongoose-keywords

JS Standard Style NPM version Build Status Coveralls Status Dependency Status Downloads

Mongoose plugin that recursively generates keywords for documents based on its fields

Install

npm install --save mongoose-keywords

Usage

Single path

var mongoose = require('mongoose');

var ArtistSchema = new mongoose.Schema({
  name: String
});

ArtistSchema.plugin(require('mongoose-keywords'), {paths: ['name']});

var Artist = mongoose.model('Artist', ArtistSchema);

var artist = new Artist({name: "L'arc~en~Ciel"});
console.log(artist.keywords); // ['larc en ciel']

Multiple path

var ArtistSchema = new mongoose.Schema({
  name: String,
  genre: String
});

ArtistSchema.plugin(require('mongoose-keywords'), {paths: ['name', 'genre']});

var Artist = mongoose.model('Artist', ArtistSchema);

var artist = new Artist({name: "L'arc~en~Ciel", genre: 'Jrock'});
console.log(artist.keywords); // ['larc en ciel', 'jrock']

Custom keywords path options

You can still define a keywords path on your schema with predefined options.

var ArtistSchema = new mongoose.Schema({
  name: String,
  keywords: {
    type: [String],
    unique: true // new custom option
  }
});

ArtistSchema.plugin(require('mongoose-keywords'), {paths: ['name']});

Custom keywords field

var ArtistSchema = new mongoose.Schema({
  name: String
});

ArtistSchema.plugin(require('mongoose-keywords'), {
  paths: ['name'],
  field: 'terms'
});

var Artist = mongoose.model('Artist', ArtistSchema);

var artist = new Artist({name: "L'arc~en~Ciel"});
console.log(artist.keywords); // undefined
console.log(artist.terms); // ['larc en ciel']

Custom transform option

By default, mongoose-keywords normalizes the value, but you can provide your own transform function.

var mongoose = require('mongoose');

var ArtistSchema = new mongoose.Schema({
  name: String
});

ArtistSchema.plugin(require('mongoose-keywords'), {
  paths: ['name'],
  transform: function (value) {
    return value + '!!!';
  }
});

var Artist = mongoose.model('Artist', ArtistSchema);

var artist = new Artist({name: "L'arc~en~Ciel"});
console.log(artist.keywords); // ["L'arc~en~Ciel!!!"]

Nested models

var mongoose = require('mongoose');
var mongooseKeywords = require('mongoose-keywords');

var GenreSchema = new mongoose.Schema({
  title: String
});
GenreSchema.plugin(mongooseKeywords, {paths: ['title']});

var ArtistSchema = new mongoose.Schema({
  name: String,
  genre: {
    type: mongoose.Schema.ObjectId,
    ref: 'Genre'
  }
});
ArtistSchema.plugin(mongooseKeywords, {paths: ['name', 'genre']});

var Genre = mongoose.model('Genre', GenreSchema);
var genre = new Genre({title: 'Jrock'});
console.log(genre.keywords); // ['jrock']

var Artist = mongoose.model('Artist', ArtistSchema);
var artist = new Artist({name: "L'arc~en~Ciel", genre: genre});
console.log(artist.keywords); // ['larc en ciel', 'jrock']

License

MIT Β© Diego Haz

mongoose-keywords's People

Contributors

diegohaz avatar greenkeeper[bot] avatar lineus avatar nickhingston avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

mongoose-keywords's Issues

An in-range update of babel-eslint is breaking the build 🚨

Version 7.2.1 of babel-eslint just got published.

Branch Build failing 🚨
Dependency babel-eslint
Current Version 7.2.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As babel-eslint is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details
Commits

The new version differs by 6 commits .

  • 3cda62e 7.2.1
  • 5626de1 Remove left over eslint 2 estraverse code (#452)
  • b5fb53b Fix type param and interface declaration scoping (#449)
  • f1cee0f Remove lodash dependency (#450)
  • eb05812 Format non-regression errors for legibility (#451)
  • 7972a05 Update README.md with codeFrame option (#448)

See the full diff.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Generate keywords from an array of object

Hi dude,

Awesome job on mongoose-keywords and all the other plugins you made for your rest api generator (querymen and bodymen are just... Waw πŸ˜ƒ )

But right now, in spite of all the awesomeness you've put in this, I'm getting stuck trying to get keywords from an array of objects that's inside my schema, here is some JSON of an object that I'd like to get keywords for:

{
    "name": "John",
    "pets": [{
        "name": "YellowBird",
        "kind": "bird"
    }, {
        "name": "PurpleDog",
        "kind": "dog"
    }]
}

I would like John's "keywords" field to be generated with ['john', 'bird', 'dog']. I tried many things like creating a petSchema but keywords get created inside pets objects and it seems like I can't access them because they are part of an object in an array.

Any clue would be really helpful since I couldn't find any on the Internet, I've been stuck for hours on this and that's the only blocking element that I met so far

Thanks for reading all of this, I hope my bad english is not making it too hard to understand :c
And of course, thanks for your help whenever you answer this πŸ˜„

Multiple keywords from one path

It would be nice if the transform function can handle arrays as return values so that a transformation can return multiple keywords.

An in-range update of eslint is breaking the build 🚨

Version 4.1.0 of eslint just got published.

Branch Build failing 🚨
Dependency eslint
Current Version 4.0.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As eslint is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ

Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Release Notes v4.1.0
  • e8f1362 Docs: Remove wrong descriptions in padded-block rule (#8783) (Plusb Preco)
  • 291a783 Update: enforceForArrowConditionals to no-extra-parens (fixes #6196) (#8439) (Evilebot Tnawi)
  • a21dd32 New: Add overrides/files options for glob-based config (fixes #3611) (#8081) (Sylvan Mably)
  • 879688c Update: Add ignoreComments option to no-trailing-spaces (#8061) (Jake Roussel)
  • b58ae2e Chore: Only instantiate fileEntryCache when cache flage set (perf) (#8763) (Gyandeep Singh)
  • 9851288 Update: fix indent errors on multiline destructure (fixes #8729) (#8756) (Victor Hom)
  • 3608f06 Docs: Increase visibility of code of conduct (fixes #8758) (#8764) (Kai Cataldo)
  • 673a58b Update: support multiple fixes in a report (fixes #7348) (#8101) (Toru Nagashima)
  • 7a1bc38 Fix: don't pass default parserOptions to custom parsers (fixes #8744) (#8745) (Teddy Katz)
  • c5b4052 Chore: enable computed-property-spacing on ESLint codebase (#8760) (Teddy Katz)
  • 3419f64 Docs: describe how to use formatters on the formatter demo page (#8754) (Teddy Katz)
  • a3ff8f2 Chore: combine tests in tests/lib/eslint.js and tests/lib/linter.js (#8746) (Teddy Katz)
  • b7cc1e6 Fix: Space-infix-ops should ignore type annotations in TypeScript (#8341) (Reyad Attiyat)
  • 46e73ee Fix: eslint --init installs wrong dependencies of popular styles (fixes #7338) (#8713) (Toru Nagashima)
  • a82361b Chore: Prevent package-lock.json files from being created (fixes #8742) (#8747) (Teddy Katz)
  • 5f81a68 New: Add eslintIgnore support to package.json (fixes #8458) (#8690) (Victor Hom)
  • b5a70b4 Update: fix multiline binary operator/parentheses indentation (#8719) (Teddy Katz)
  • ab8b016 Update: fix MemberExpression indentation with "off" option (fixes #8721) (#8724) (Teddy Katz)
  • eb5d12c Update: Add Fixer method to Linter API (#8631) (Gyandeep Singh)
  • 26a2daa Chore: Cache fs reads in ignored-paths (fixes #8363) (#8706) (Victor Hom)
Commits

The new version differs by 22 commits.

  • 7d9e3be 4.1.0
  • e727b7b Build: changelog update for 4.1.0
  • e8f1362 Docs: Remove wrong descriptions in padded-block rule (#8783)
  • 291a783 Update: enforceForArrowConditionals to no-extra-parens (fixes #6196) (#8439)
  • a21dd32 New: Add overrides/files options for glob-based config (fixes #3611) (#8081)
  • 879688c Update: Add ignoreComments option to no-trailing-spaces (#8061)
  • b58ae2e Chore: Only instantiate fileEntryCache when cache flage set (perf) (#8763)
  • 9851288 Update: fix indent errors on multiline destructure (fixes #8729) (#8756)
  • 3608f06 Docs: Increase visibility of code of conduct (fixes #8758) (#8764)
  • 673a58b Update: support multiple fixes in a report (fixes #7348) (#8101)
  • 7a1bc38 Fix: don't pass default parserOptions to custom parsers (fixes #8744) (#8745)
  • c5b4052 Chore: enable computed-property-spacing on ESLint codebase (#8760)
  • 3419f64 Docs: describe how to use formatters on the formatter demo page (#8754)
  • a3ff8f2 Chore: combine tests in tests/lib/eslint.js and tests/lib/linter.js (#8746)
  • b7cc1e6 Fix: Space-infix-ops should ignore type annotations in TypeScript (#8341)

There are 22 commits in total.

See the full diff

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Require default

README example doesn't work. require('mongoose-keywords')

Updating nested keywords only works when we save the object with the nested object populated with keywords

If we save a object without populating the nested objects we lose the nested keywords. The modified example below shows the issue.

  var mongoose = require('mongoose');
  var mongooseKeywords = require('mongoose-keywords');

  var GenreSchema = new mongoose.Schema({
    title: String
  });
  GenreSchema.plugin(mongooseKeywords, {paths: ['title']});

  var ArtistSchema = new mongoose.Schema({
    name: String,
    genre: {
      type: mongoose.Schema.ObjectId,
      ref: 'Genre'
    }
  });
  ArtistSchema.plugin(mongooseKeywords, {paths: ['name', 'genre']});

  var Genre = mongoose.model('Genre', GenreSchema);
  var genre = new Genre({title: 'Jrock'});
  console.info(genre.keywords); // ['jrock']

  var Artist = mongoose.model('Artist', ArtistSchema);
  var artist = new Artist({name: "L'arc~en~Ciel", genre: genre._id}); /* genre saved as object id */
  console.info(artist.keywords); // ['larc en ciel', 'jrock']

Lets say I want to add a query with querymen...

Right now everything works great, but, as I understand, I can add a query to the request too.
I have http://IP:PORT/guildmembers?access_token=MyToken&sort=nick&limit=100&page=1&fields=discordId%2C%20nick%2C%20roles working flawlessly, and showing 100 documents with discordId, nick and roles.
Roles is an array, and I would like to query then to those users who have an specific role...lets say, boss.
I tried adding different combinations of {"roles": {$all: ["Boss"]}}, but I never get a document in response when adding the query. I don't really understand how mongoose-keywords works, tbh, and Idk if I should add something to my schema.
Any help'll be very appreciated :)

Generate keywords from existing documents

Hi!

I'm rebuilding my API to one generated with generator-rest (great work BTW), but I'm facing an issue.
I noticed that querying the API only works for documents posted to the endpoint generated by generator-rest. I suppose it calls mongoose-keywords to generate the keywords, so it will only find those.

Is there a way to generate the keywords for the 1800 documents I already have in my database, that were posted prior to using generator-rest?

Thanks in advance!

Combine custom keywords path options and nested models

The mongoose-keywords supports type: unique to a column and/or relation?
Is it possible to combine it with nested-models?

Related: #11

const ArtistSchema = new Schema({
  name: {
    type: String,
    keywords: {
      type: [String],
      unique: true,
    },
  },
  genre: {
    type: Schema.Types.ObjectId,
    ref: 'Genre',
  },
});
ArtistSchema.plugin(mongooseKeywords, { paths: ['name', 'genre'] });

Broken in Mongoose 5.x.x

Hey,
I just tried mongoose-keywords with querymen (from the yeoman rest template) and upgraded all the packages; keywords seems to break with Mongoose 5.0.x, I'm afraid.
Offending line is:
this[field].addToSet(transform(value))
since this[field] is undefined.
Thanks!

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.