My friends, friends, unfortunately, I can not find examples of how to implement the bluebird promise library in the node js express mongoose application.
My application is set up where the mongoose model, controllers and routes are in different files.
But realizing it with the help of mongoose, I just can not understand it.
So, please, someone will show me how it is used. See below.
//express controller Article.js var mongoose = require('mongoose'), errorHandler = require('./errors'), Article = mongoose.model('Article'); exports.list = function(req, res) { Article.find().sort('-created').populate('user', 'displayName').exec(function(err, articles) { if (err) { return res.status(400).send({ message: errorHandler.getErrorMessage(err) }); } else { res.jsonp(articles); } }); };
// Mongoose Model
var mongoose = require('mongoose'), Schema = mongoose.Schema; var ArticleSchema = new Schema({ created: { type: Date, default: Date.now }, title: { type: String, default: '', trim: true, required: 'Title cannot be blank' }, content: { type: String, default: '', trim: true }, user: { type: Schema.ObjectId, ref: 'User' } }); mongoose.model('Article', ArticleSchema);
So please, if I wanted to use the Bluebird promise library, how would I go about changing export.list
Thanks in advance.
Some questions,
where can i call the promisify mongoose model? e.g. Article = mongoose.model('Article'); like this Article = mongoose.model('Article'); like this Article = Promise.promisifyAll (require ('Article')); or how is it
var Article = mongoose.model('Article'); Article = Promise.promisifyAll(Article);