These are chat archives for Automattic/mongoose

2nd
Jan 2018
Works great! Some breaking changes, but that's ok – I've waited for this release! 👌
Nick Karnik
@theoutlander
Jan 02 2018 07:54
:+1:
Nick Karnik
@theoutlander
Jan 02 2018 16:09
Hello! Can a pre(‘save’,…) hook be added once the schema is part of a model? In my tests, it doesn’t seem to work if I add it to the schema after I require the model. However, it works if I do it inside the schema file before it is wrapped by the model. Can anyone confirm this please?
Nick Karnik
@theoutlander
Jan 02 2018 16:15
I guess it seems like it might be similar to this issue here Automattic/mongoose#5897
The above issue seems related to inheritance … mine isn’t
Jacob Hoke
@threads13
Jan 02 2018 22:04
@theoutlander Ok... I think I figured out where I was confused. It seems like the push and save is not working. When I run this code shouldn't I see the value "Test Comments" stored in my DB? I looked in my DB and I don't see it.
app.get("/blogs/:id/comments", function(req, res){
    var id = mongoose.Types.ObjectId();
    var comment = "Test comments";
    Blog.findById(req.params.id, function(err, blog){
        blog.comments.push(id);
        blog.save();
        // console.log(blog);
        // blogschema.findOne({author: 'asdasd'}).populate('comments').exec(function (err, comments) {console.log(comments)})

    });
    Blog.findOne({author: 'nick'}).populate('comments').exec(function (err, comments) {console.log(comments)})

    res.send("Test");
});
Nick Karnik
@theoutlander
Jan 02 2018 22:08
You aren’t adding the comment to your comments ?
@threads13 you should see the id in the db
on the blog
Jacob Hoke
@threads13
Jan 02 2018 22:12
yeah, I just noticed that I didn't add comment right after I typed that, but I still don't see that "Test Comments" in there
Philip Esmailzade
@Paikz
Jan 02 2018 23:06
Hey guys, im doing a social media clone as a beginner. I have a user schema and a post schema. I'm trying to get posts from all the users im following. Any tips on how to do that?
//Relevant code
var postSchema = mongoose.Schema({
    username: {
        type: String,
        lowercase: true,
        required: true,
    }
});

var userSchema = mongoose.Schema({
    username: {
        type: String,
        unique: true,
        dropDups: true,
        lowercase: true,
        required: true,
        trim: true
    },
    //Stores usernames, not id
    following: [{ type: String, ref: 'User' }],
    followers: [{ type: String, ref: 'User' }]
});
Richard Schulte
@acao
Jan 02 2018 23:41
has anyone here had success with mongoose-revisionist?