mongoose-extended-filter

1.3.4 • Public • Published

mongoose-extended-filter Build Status

Extended filter for Mongoose

Use

const mongoose = require('mongoose');
const mongooseExtendedFilter = require('mongoose-extended-filter');
 
const treeSchema = new mongoose.Schema({
  name: String
});
 
const branchSchema = new mongoose.Schema({
  name: String,
  tree: {
    type: ObjectId,
    ref: 'Tree'
  }
});
 
treeSchema.plugin(mongooseExtendedFilter);
branchSchema.plugin(mongooseExtendedFilter);
 
const Tree = mongoose.model('Tree', treeSchema);
const Branch = mongoose.model('Branch', branchSchema);
 
Branch.prepareConditions({tree: {name: 'Billy'}})
  .then(conditions => {
    // conditions = {tree: {$in: [...]}
    return Branch.find(conditions).exec();
  })
  .then(branches => {
    // some code
  });
 
// or with dot-notation
Branch.prepareConditions({'tree.name': 'Billy'})
  .then(conditions => {
    // conditions = {tree: {$in: [...]}
    return Branch.find(conditions).exec()
  })
  .then(branches => {
    // some code
  });

Package Sidebar

Install

npm i mongoose-extended-filter

Weekly Downloads

21

Version

1.3.4

License

ISC

Last publish

Collaborators

  • dmitry_smv
  • denisbezrukov
  • zbit
  • alekns
  • takatan
  • vasiliykuznetsov