mongoose-transactions icon indicating copy to clipboard operation
mongoose-transactions copied to clipboard

Mongo operator starting with $ not working

Open mirajaonison opened this issue 6 years ago • 3 comments

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
        });
    });

mirajaonison avatar Nov 30 '17 05:11 mirajaonison

This issue is closed due to inactivity

topperblues avatar Apr 17 '18 09:04 topperblues

@rajaonison thank you for your report... we'll fix this error with the new version of the module

daton89 avatar Apr 17 '18 21:04 daton89

Has this problem been solved?I had the same problem today, update conditions didn't work

msbolang avatar Nov 14 '19 10:11 msbolang