Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
a promise example
const mongoose = require('mongoose');
const Store = mongoose.model('Store');
const StoreB = mongoose.model('StoreB');
// Tells package to use es6 promises
mongoose.Promise = global.Promise;
exports.createStore = (req, res) => {
const store = new Store(req.body);
const record_we_want_to_associate
.findOne({ id: req.params._id})
.catch(err => {
throw Error(err);
store.storeb_id = record_we_want_to_associate._id
// after save return all records
.then(stores => {
return Store.find()
// then display them on index page
.then(stores => {
res.render('index', {stores: stores}
// deal with errors
.catch(err => {
throw Error(err)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.