Skip to content
This repository has been archived by the owner on Aug 10, 2019. It is now read-only.

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

License

Notifications You must be signed in to change notification settings

fabiospampinato/mongoose-findanyoneorcreate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published