1.0.3 • Published 5 years ago

mongoose-findanyoneorcreate v1.0.3

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

findAnyoneOrCreate

Promise-based plugin for Mongoose that defines a "findAnyoneOrCreate" static method.

Useful for finding a document, with support for creating it if doesn't exist already.

Install

$ npm install --save mongoose-findanyoneorcreate

Usage

import * as mongoose from 'mongoose';
import findAnyoneOrCreate from 'mongoose-findanyoneorcreate';
import BookSchema from './book_schema';

BookSchema.plugin ( findAnyoneOrCreate );

const model = mongoose.model ( 'Book', BookSchema );

const book = await model.findAnyoneOrCreate ({
  title: 'My book title',
  author: 'Me',
  category: 'fantasy'
});

Related

  • findOneOrCreate - Promise-based plugin for Mongoose that defines a "findOneOrCreate" static method.

License

MIT © Fabio Spampinato