@naxmefy/mongoose-fex
v0.1.0
Published
added several methods the mongoose schema to find, update or create documents. fex = find extensions
Downloads
2
Readme
node-mongoose-fex
added several methods the mongoose schema to find, update or create documents. fex = find extensions
Prerequisites
you have to define a promise library in your mongoose installation, like:
const mongoose = require('mongoose')
const Promise = require('bluebird')
mongoose.Promise = Promise
Installation
$ npm install --save @naxmefy/mongoose-fex
Usage
Global
const mongoose = require('mongoose')
const mongooseFex = require('@naxmefy/mongoose-fex')
mongoose.plugin(mongooseFex)
Per Schema
const mongoose = require('mongoose')
const mongooseFex = require('@naxmefy/mongoose-fex')
const schema = new mongoose.Schema({})
schema.plugin(mongooseFex)
API
findBy (String, Any [, Function])
model.findBy('test', testValue, function (err, documents) {})
Hint: The plugin also creates findBy shortcuts per defined path
findBy{Key} (Any [, Function])
const schema = new mongoose.Schema({ test: String }) schema.plugin(mongooseFex) const model = mongoose.model('TestSchema', schema) model.findByTest(testString, function (err, documents) { if (err) return console.error(err) console.log(documents) })
findOneBy (String, Any [, Function])
model.findOneBy('test', testValue, function (err, document) {})))
Hint: The plugin also creates findOneBy shortcuts per defined path
findOneBy{Key} (Any [, Function])
const schema = new mongoose.Schema({ test: String }) schema.plugin(mongooseFex) const model = mongoose.model('TestSchema', schema) model.findOneByTest(testString, function (err, document) { if (err) return console.error(err) console.log(document) })
findOneOrCreate (Object, Object [, Function])
model.findOneOrCreate({test: 'test'}, {test: 'test'}, function (err, document) {})))
findByOrCreate (String, Array [, Function])
model.findByOrCreate('test', [{test: 'test1'}, {test: 'test2'}], function (err, documents) {})))
findOneByOrCreate (String, Object [, Function])
model.findOneByOrCreate('test', {test: 'test'}, function (err, document) {})))