@naxmefy/mongoose-fex
added several methods the mongoose schema to find, update or create documents. fex = find extensions
Last updated 4 years ago by naxmefy .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @naxmefy/mongoose-fex 
SYNC missed versions from official npm registry.

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<Object> [, Function])

model.findByOrCreate('test', [{test: 'test1'}, {test: 'test2'}], function (err, documents) {})))

findOneByOrCreate (String, Object [, Function])

model.findOneByOrCreate('test', {test: 'test'}, function (err, document) {})))

Current Tags

  • 0.1.0                                ...           latest (4 years ago)

1 Versions

  • 0.1.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (5)
Dev Dependencies (9)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |