mongoose-findanyoneorcreate
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i mongoose-findanyoneorcreate

Weekly Downloads

0

Version

1.0.3

License

MIT

Unpacked Size

5.17 kB

Total Files

8

Last publish

Collaborators

  • fabiospampinato