There is such a document structure in MongoDB
{ "_id" : ObjectId("58f7d556aa52ce456672a67e"), "created" : ISODate("2017-04-19T21:23:34.315Z"), "context_task" : [ { "task" : "напишем немного текста ", "status" : false, "_id" : ObjectId("58f7d559aa52ce456672a67f") } ], "head" : { "userID" : "58f48037fc894e19a3f7b81b", "head_task" : "пробный забег " }, "__v" : 0 } Add data to context_task.task using the following query
task.update({"_id": req.body.id_project}, {$push: {'context_task': {'task': req.body.input_task,'status': false}}}, function (err) { if (err) return next(err); var body = req.body.id_project+","+req.body.input_task; res.status(200).send(body); }); Tell me, how can I get the context_task._id of a new record after insertion? I tried to send the second parameter to the callback, but it returns only the status of the request.
function (err, doc) { if (err) return next(err); console.log(doc); //output -> { n: 1, nModified: 1, ok: 1 } res.status(200).send(); });