All Projects → drudge → Mongoose Findorcreate

drudge / Mongoose Findorcreate

Licence: other
Simple plugin for Mongoose which adds a findOrCreate method to models.

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Mongoose Findorcreate

Api Query Params
Convert URL query parameters to MongoDB queries
Stars: ✭ 141 (-17.54%)
Mutual labels:  mongoose
React Express Blog Demo
🔥 React full stack+Express+Mongo implementation blog website tutorial 🌚
Stars: ✭ 1,857 (+985.96%)
Mutual labels:  mongoose
Frisky
🍿 Open Source GraphQL API for Online Shows
Stars: ✭ 161 (-5.85%)
Mutual labels:  mongoose
Nest User Auth
A starter build for a back end which implements managing users with MongoDB, Mongoose, NestJS, Passport-JWT, and GraphQL.
Stars: ✭ 145 (-15.2%)
Mutual labels:  mongoose
Node Express Mongo Api
Starter project for a REST API with Node.js, Express & MongoDB 🔋
Stars: ✭ 148 (-13.45%)
Mutual labels:  mongoose
Nodejs
This project provides Scala.js type-safe bindings for Node.js (current) v8.7.0 and LTS v6.11.4 APIs. The platform supports MEAN (MongoDB, Express, AngularJs, NodeJS), Cassandra, MySQL and many other npm projects.
Stars: ✭ 152 (-11.11%)
Mutual labels:  mongoose
Fastify Api
A blazing fast REST APIs with Node.js, MongoDB, Fastify and Swagger.
Stars: ✭ 138 (-19.3%)
Mutual labels:  mongoose
Mongoose Autopopulate
Always populate() certain fields in your mongoose schemas
Stars: ✭ 170 (-0.58%)
Mutual labels:  mongoose
Node Easy Notes App
A simple Note-Taking app built using Node.js, Express and Mongoose
Stars: ✭ 148 (-13.45%)
Mutual labels:  mongoose
Mongoose Typescript Example
Stars: ✭ 156 (-8.77%)
Mutual labels:  mongoose
Forest Express Mongoose
🌱 Express/Mongoose Liana for Forest Admin
Stars: ✭ 145 (-15.2%)
Mutual labels:  mongoose
Koa Restful Boilerplate
Koa 2 RESTful API boilerplate
Stars: ✭ 146 (-14.62%)
Mutual labels:  mongoose
Next Graphql Blog
🖊 A Blog including a server and a client. Server is built with Node, Express & a customized GraphQL-yoga server. Client is built with React, Next js & Apollo client.
Stars: ✭ 152 (-11.11%)
Mutual labels:  mongoose
Gindex V4
A Vue Js Based G Index with Improved Dark Mode, Search and Video Player
Stars: ✭ 143 (-16.37%)
Mutual labels:  mongoose
Nestjs Mongoose Crud
Nest.js crud module for mongoose models without `nestjsx/crud`
Stars: ✭ 164 (-4.09%)
Mutual labels:  mongoose
Express Oas Generator
OpenAPI (Swagger) specification generator for ExpressJS applications
Stars: ✭ 138 (-19.3%)
Mutual labels:  mongoose
Amazona
Build Ecommerce Like Amazon By MERN Stack
Stars: ✭ 152 (-11.11%)
Mutual labels:  mongoose
Lad
👦 Lad is the best Node.js framework. Made by a former Express TC and Koa team member.
Stars: ✭ 2,112 (+1135.09%)
Mutual labels:  mongoose
Ecommerce Site Template
A beautiful e-commerce template powered by React, Redux and other modern web tech.
Stars: ✭ 167 (-2.34%)
Mutual labels:  mongoose
Nauth Restful Api
Node.js+Mongoose的RestfulApi的用户token权限验证(just a demo)
Stars: ✭ 155 (-9.36%)
Mutual labels:  mongoose

Mongoose findOrCreate Plugin Build Status

Simple plugin for Mongoose which adds a findOrCreate method to models. This is useful for libraries like Passport which require it.

Installation

npm install mongoose-findorcreate

Usage

var findOrCreate = require('mongoose-findorcreate')
var ClickSchema = new Schema({ ... });
ClickSchema.plugin(findOrCreate);
var Click = mongoose.model('Click', ClickSchema);

The Click model now has a findOrCreate static method

Click.findOrCreate({ip: '127.0.0.1'}, function(err, click, created) {
  // created will be true here
  console.log('A new click from "%s" was inserted', click.ip);
  Click.findOrCreate({}, function(err, click, created) {
    // created will be false here
    console.log('Did not create a new click for "%s"', click.ip);
  })
});

You can also include properties that aren't used in the find call, but will be added to the object if it is created.

Click.create({ip: '127.0.0.1'}, {browser: 'Mozilla'}, function(err, val) {
  Click.findOrCreate({ip: '127.0.0.1'}, {browser: 'Chrome'}, function(err, click) {
    console.log('A click from "%s" using "%s" was found', click.ip, click.browser);
    // prints A click from "127.0.0.1" using "Mozilla" was found
  })
});

Promise Support

Choose your Promise library by setting Mongoose.Promise.

The returned Promise shall resolve to an object with keys doc and created on success. It shall be rejected with err on failure.

// Use environment-provided Promise (necessary to silence a Mongoose warning).
mongoose.Promise = Promise;
// To a findOrCreate().
Click.findOrCreate({ip: '127.0.0.2'}).then(function (result) {
  click = result.doc;
  console.log('A click from', click.ip, ' using ', click.browser, ' was ', click.created ? 'created' : 'found');
})

License

(The MIT License)

Copyright (c) 2012-2017 Nicholas Penree <[email protected]>

Based on supergoose: Copyright (c) 2012 Jamplify

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].