• This repository has been archived on 03/May/2023
  • Stars
    star
    122
  • Rank 292,031 (Top 6 %)
  • Language
    JavaScript
  • Created over 11 years ago
  • Updated almost 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

**DEPRECATED** kriskowal's Q support for mongoose

mongoose-q

DEPRECATED [ES6 Promise is supported]((http://mongoosejs.com/docs/harmony.html) by mongoose officially.

kriskowal's Q support for mongoose.

for mongodb native nodejs driver, see mongo-q.

usage

to apply Q with default suffix 'Q':

var mongoose = require('mongoose-q')(require('mongoose'));
// verbose way: mongooseQ is unused
var mongoose = require('mongoose'),
    mongooseQ = require('mongoose-q')(mongoose)
// shortest way: mongoose will be loaded by mongoose-q
var mongoose = require('mongoose-q')();

to apply another Q implementation(since v0.0.15):

// to use bluebird
var mongoose = require('mongoose-q')(require('mongoose'), {q:require('q-bluebird')});

use Q-applied model statics:

SomeModel.findByIdQ(....blahblah...)
  .then(function (result) { ... })
  .catch(function (err) { ... })
  .done();

use Q-applied model methods:

var someModel = new SomeModel(...);
someModel.populateQ()
  .then(function (result) { ... })
  .catch(function (err) { ... })
  .done();

use Q-applied query methods:

SomeModel.find(...).where(...).skip(...).limit(...).sort(...).populate(...)
  .execQ() // no 'Q' suffix for Query methods except for execQ()
  .then(function (result) { ... })
  .catch(function (err) { ... })
  .done();

use Q-applied aggregate methods:

SomeModel.aggregate(...).project(...).group(...).match(...).skip(...).limit(...).sort(...).unwind(...)
  .execQ() // no 'Q' suffix for Aggregate methods except for execQ()
  .then(function (result) { ... })
  .catch(function (err) { ... })
  .done();

to apply Q with custom suffix/prefix:

var mongoose = require('mongoose-q')(require('mongoose'), {prefix:'promiseOf_', suffix:'_withQ'});
SomeModel.promiseOf_findAndUpdate_withQ(...)
  .then(function (result) { ... })
  .catch(function (err) { ... })
  .done();

to apply Q with custom name mapper:

function customMapper(name) {
  return 'q' + name.charAt(0).toUpperCase() + name.substring(1);
}
var mongoose = require('mongoose-q')(require('mongoose'), {mapper:customMapper});
SomeModel.qFindAndUpdate(...)
  .then(function (result) { ... })
  .catch(function (err) { ... })
  .done();

DEPRECATED to apply Q with spread:

NOTE: since mongoose 4.x: no spread for update()!

NOTE: without spread option(by default), you can access only the first result with then!!

var mongoose = require('mongoose-q')(require('mongoose'), {spread:true});
SomeModel.createQ(doc1, doc2, ...)
  .spread(function (saved1, saved2, ...) { ... })
  .catch(function (err) { ... })
  .done();
SomeModel.createQ(doc1, doc2, ...)
  .then(function (result) { var saved1 = result[0], raw = saved1[1]; ... })
  .catch(function (err) { ... })
  .done();
...
var model = new SomeModel();
...
model.saveQ()
  .spread(function (savedDoc, affectedRows) { ... })
  .catch(function (err) { ... })
  .done();
...
model.saveQ()
  .then(function (result) { var savedDoc = result[0], affectedRows = result[1]; ... })
  .catch(function (err) { ... })
  .done();

to define custom statics/instance methods using Q

NOTE: this is not a feature of mongoose-q

SomeSchema.statics.findByName = function (name) {
  return this.findQ({name: name}); // NOTE: returns Promise object.
};
...
var SomeModel = mongoose.model('Some', SomeSchema);
SomeModel.findByName('foo').then(function(result) {
  console.log(result);
});

That's all folks!

More Repositories

1

hellowebapp-android

How to build Android App with HTML5/CSS/JavaScript
Java
24
star
2

pictor

simple image upload/convert/download server.
JavaScript
19
star
3

spring-template-bench

spring template benchmark with script template and react server-side- rendering et all
Java
13
star
4

mongolfier

**DEPRECATED** mysql to mongodb migration tool
JavaScript
13
star
5

playnode-springboard-demo

java/spring + nodejs + thrift + react demo for playnode 2015
JavaScript
12
star
6

mongo-q

**DEPRECATED** kriskowal's Q support for mongodb
JavaScript
6
star
7

hellowebapp-atom

boilerplate webapp using atom-shell
JavaScript
6
star
8

express-toybox

My Own Extra Stuff for Express
JavaScript
5
star
9

node-nobatis

simple "mybatis-like" dao for nodejs
JavaScript
5
star
10

kotlin-boot-jpa-wordpress

Kotlin + Spring Boot + JPA samples with WordPress Database
PHP
5
star
11

blueberryseason

blueberryseason is a minimal discussion forum(aka bbs) to demonstrate various webapp architectures.
JavaScript
4
star
12

jscon-springboard-demo

jscon 2016 demo: react isomorphic rendering with java/spring/j2v8
JavaScript
4
star
13

commonjs

**deprecated** PoC implementaion for browser with useful and/or useless modules
JavaScript
3
star
14

redis-q

**DEPRECATED** kriskowal's Q and JSON support for node_redis.
JavaScript
3
star
15

node-noredis

simple shared storage for workers in nodejs cluster
JavaScript
3
star
16

spring-five-expedition

learn spring 5 new features by example
Java
3
star
17

httpspell

httpspell is a simple http binding for hunspell.
JavaScript
2
star
18

mongoose-toybox

my own extra stuff for mongoose
JavaScript
2
star
19

slideshare-exporter

Export all uploaded slides from slideshare
JavaScript
2
star
20

debug-browser

**deprecated** tjholowaychuk's debug clone for browser environment
JavaScript
2
star
21

http-from-scratch

Just for Fun ;)
JavaScript
2
star
22

methuss

html meta tags(opengraph/twittercard) fetch/parse/cache server.
JavaScript
1
star
23

X2Kbd

Use the Daewoo MSX2 X-2 (CPC-400) Keyboard with Modern PC via PS/2(via arduino pro micro USB Port)
C++
1
star
24

vim-markdown-preview

minimal vim plugin for markdown preview using `marked` and `open` command.
Vim Script
1
star
25

monoon

dot dot dot!
HTML
1
star
26

node-packagestyle

java package style module loader
JavaScript
1
star
27

hellowebapp-ios

How to build iPhone App with HTML5/CSS/JavaScript
Objective-C
1
star
28

n2pm

**DEPRECATED** n2pm is NOT a Node Package Manager.
JavaScript
1
star
29

7x12-fonts

HTML
1
star
30

esp8266-wifi-modem

C++
1
star
31

sun-type6-keyboard

Sun Type6 Keyboard(din8 type) to USB HID converter using Arduino Pro Micro
C++
1
star
32

call3327

The very first Korean(Hangul) Input/Output Program for Old 8-bit Apple II series computers.
Assembly
1
star