These are chat archives for Automattic/mongoose

8th
Jul 2017
krasevych
@krasevych
Jul 08 2017 09:12
Hi, I have a question: what is difference between User.findOne(...).exec().then(...) and User.findOne(...).then(...)?
Nicholai Nissen
@Nicholaiii
Jul 08 2017 11:41
@deathlover Just make a virtual:
Schema.virtual('createdAtMoment')
.get(function(){
  return moment(this.created_at)
})
Dennis Belany
@azarus
Jul 08 2017 11:48
hi
anyone here? :)
davegahn
@davegahn
Jul 08 2017 21:28
Hello. How can I use two bodels when rendering a page?
const express = require('express');
const router = express.Router();
const mongoose = require('mongoose');
const content = require('../views/data/content.json');

router.get('/', function (req, res) {
  let obj = {
    title: 'My works',
    reviews: content.reviews
  };
  Object.assign(obj, req.app.locals.settings);

  const Model = mongoose.model('pic');
  Model
    .find()
    .then(items => {
      Object.assign(obj, {items: items});
      res.render('pages/works', obj);
    });


  const Model2 = mongoose.model('reviews');
  Model2
    .find()
    .then(reviews => {
      Object.assign(obj, {ReviewList: reviews});
      res.render('pages/works', obj);
    });
});
davegahn
@davegahn
Jul 08 2017 21:33
This doesn't work...