相关疑难解决方法(0)

CastError:转换为字符串的值失败

我想创建一个交易模块,在成功交易后,用户文档(在这种情况下用户向另一个用户汇款)也将被更新。

一种。在 user.js(这是用户模型)中,除了姓名、密码、电子邮件(等)我创建了这个属性,它将保存各个用户的交易相关历史记录。请看看我是如何使用它的:

transaction_history:[{
            transactionid:String,
            timestamp:String,
            type:String,
            balance:Number,
            status:String

        }]
Run Code Online (Sandbox Code Playgroud)

湾 当发件人点击表单中的发送按钮时,会创建一个交易文档,然后用户文档(这里是发件人)应该与交易信息一起更新。

//create transaction document, works fine
Transaction.create({transactionid:uniqid(),
                timestamp:moment().format(datemask),
                amount:balance,
                sender:sendfrom,
                receiver:sendto,
                status:"done"
}, function(err, tr){
    if(err) throw err;
    else {

        //I want sender document to update with transaction info
        User.findOne({email:sendfrom}, function(err, sendfrom){
            if(err) {console.log("error at sender side");}
            else 
            if(sendfrom!=null){
                // console.log("tr: "+tr); //fine
                sendfrom.balance-=balance;
                sendfrom.transaction_history.push({

                     transactionid:tr.transactionid, 


                    // timestamp:tr.timestamp,
                    // type:"debit",
                    // balance:tr.amount,
                    // status:tr.status 

                }
                );
                sendfrom.save();
                console.log("sender's current balance is: "+sendfrom.balance);


            };
            });
            }});
Run Code Online (Sandbox Code Playgroud)

C。但后来我得到了这个:

events.js:163
  throw er; …
Run Code Online (Sandbox Code Playgroud)

mongoose nosql node.js

1
推荐指数
1
解决办法
6397
查看次数

标签 统计

mongoose ×1

node.js ×1

nosql ×1