mongoose-transactions
mongoose-transactions copied to clipboard
Mongo operator starting with $ not working
Using operators like $in, $ne, $push gives an error : UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): Error: key $push must not start with '$' @daton89 If you use mongoose to do the query, it works.
// Code using mongoose-transactions : not working
let transaction = new Transaction(true);
let replyId = transaction.insert("Comment", new Comment(req.body));
transaction.update("Comment", req.params.id, {$push: {replies: replyId} });
try{
transaction.run();
return res.status(200).json({
status : "Reply inserted"
});
}
catch(error){
transaction.rollback().catch((error) => {
return res.status(500).json({
status: "Error on replying",
error: error.message
});
});
}
// Code using mongoose : working
Comment.update({_id:req.params.id},{$push: {replies: req.params.id} }).then((data)=>{
return res.status(200).json({
status : "Reply inserted"
});
}).catch((error)=>{
console.log(error);
return res.status(500).json({
status: "Error on replying",
error: error.message
});
});
This issue is closed due to inactivity
@rajaonison thank you for your report... we'll fix this error with the new version of the module
Has this problem been solved?I had the same problem today, update conditions didn't work