node.js - mongodb not responding after save -


i using mongoose express.js project.

here article model:

var articleschema = new schema({      type: string     ,title: string     ,content: string      ,comments: [{         type: schema.objectid         ,ref: 'comment'     }]      ,replies: [{         type: schema.objectid         ,ref: 'reply'     }]       ,feedbacks: [{         type: schema.objectid         ,ref: 'feedback'     }]       ,meta: {         tags: [string] //anything         ,apps: [{             store: string //app store, google play, amazon app store             ,storeid: string         }]         ,category: string     }       , status: string     ,statusmeta: {         createdby: {             type: schema.objectid             ,ref: 'user'         }         ,createddate: date         , updatedby: {             type: schema.objectid             ,ref: 'user'         }         ,updateddate: date          ,deletedby: {             type: schema.objectid,             ref: 'user'         }         ,deleteddate: date          ,undeletedby: {             type: schema.objectid,             ref: 'user'         }         ,undeleteddate: date          ,bannedby: {             type: schema.objectid,             ref: 'user'         }         ,banneddate: date         ,unbannedby: {             type: schema.objectid,             ref: 'user'         }          ,unbanneddate: date     } }, {minimize: false}) 

this controller function

exports.createarticle = function(req, res, next) {      //1. save article     var newarticle = new article()     newarticle.status = helper.constant.entitystatus.normal     newarticle.type = req.body.type     newarticle.category = req.body.category     newarticle.title = req.body.title     newarticle.content = req.body.content     //comments omit     //replies omit     //feedbacks omit     newarticle.meta = req.body.meta     newarticle.statusmeta.createdby = req.user     newarticle.statusmeta.createddate = new date     newarticle.save(function(err) {         if (err)             return next(err)          //2. add article user         req.user.articles.push(newarticle)         req.user.save(function(err) {             if (err)                 return next(err)              //3. refetch article, done             var query = article.findbyid(newarticle._id)             helper.populatecommonfieldsforquery(query)             query.exec(function(err, article) {                 if (err)                     return next(err)                 if (! article)                     return next(helper.getgeneralerror('unable fetch saved article'))                 return res.json(helper.dataappendedwithmessage(article.tojson(), 'success', 'successfully created article'))             })         })      }) } 

when create article meta.tags empty array, works. if tags not empty, save callback (function(err) {})is not fired.

before save write this:

newarticle.markmodified('meta'); 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -