These are chat archives for Automattic/mongoose

2nd
Jul 2017
John Brosan
@jbrosan
Jul 02 2017 01:08

Hello everyone, I am new to Mongoose. I'm having an issue when I make a simple find call, Mongoose seems to just hang without any errors. I can see where the app makes the connection, but nothing after that. I've got a collection called, "post" and a schema/model contained in a separate directory

const mongoose = require('mongoose');
mongoose.Promise = global.Promise;
const post = new mongoose.Schema({
    title: String,
    author: String,
    body: String,
    comments: [{
        body: String, data: Date
    }],
    date: {
        type: Date, default: Date.now
    },
    hidden: Boolean,
    meta: {
        votes: Number,
        favs: Number
    }

});

const Post = mongoose.model('Post', post);
module.exports  =  Post;

I'm using Koa.js (but have tried express as well)

...
const mongoose = require('mongoose');
const Post = require('./src/models/PostModel');
...
router.get('/api/posts', async (ctx) => {
    try {
        let results = await Post.find().exec();
        ctx.body = results;
    } catch(err) {
        console.log(err);
    }
});
...

Any suggestions or help would be most appreciated. I am sure its something that I've missed or messed up. LOL

szpakowski
@szpakowski
Jul 02 2017 21:33
@jbrosan John, I am also new to mongoose and not really a programmer but this sounds like a similar problem I had yesterday where no matter what I did the query would just hang. What version of mongoose are you using? Please see this link Automattic/mongoose#5399. Hope this helps.
Joshua Austill
@jlaustill
Jul 02 2017 21:57
@jbrosan @szpakowski I was having this issue anytime I had a sub-document. I wasted enough time I finally just switched back to the native driver