These are chat archives for Automattic/mongoose

28th
Feb 2017
Ankur sharma
@ankur1163
Feb 28 2017 08:04 UTC
I have weird problem in mongoose
i try to update
but neither i get error neither response
its jut when mongoose query starts
after that nothing happens
can mongoose guru help me out?
Ankur sharma
@ankur1163
Feb 28 2017 08:14 UTC
 create:function(params,callback){
        console.log("req",params.body);
        var username = params.username;
        var title = params.title;
        var img = params.myimages;
        var resource = params.resource;
        console.log("entered in images controller create");

        console.log("image post router",title,"img",img,"resource",resource,"username",username)
        Images.findOneAndUpdate(
            { "username": "ankur" },
            {
                $push: { "myimages": { "img": img, "hearts": 0, "title": title } }
            },
            {
                new: true,   // return new doc if one is upserted
                upsert: true // insert the document if it does not exist
            },
            function (err, resp) {
                if (err) {
                    console.log("there is err in image controller");
                    callback(err, null);
                } else {
                    console.log("good in image controller");
                    callback(null, resp);
                }
            });

    }
var mongoose = require('mongoose');

var ImagesSchema = new mongoose.Schema({
    username:{type:String},
    myimages: [{
        img: String,
        hearts: Number,
        title: String
    }],
    thosewhovoted:{type:Array,default:[]}


});

module.exports = mongoose.model('ImagesSchema', ImagesSchema);