在模型“钱包”的路径“ _id”处,值“ me”的强制转换为ObjectId

大家好,我想在一个节点中获取用户的数据。表示单个用户的所有数据。像这样一个寄存器数据,     其他是付款。现在,我想获得所有关于如何     用户已经支付了很多。我已经试过了。但是这个错误来了     也许我无法正确编写代码。所以请指导我。

获取用户付款方式

router.get('/me', auth, async (req, res) => {
    UserWallet.find()
        .select("user", " id user")
        .populate("user ", "_id user")
        .exec()
        .then(result => {
            res.json({ result })
        })
        .catch(error => {
            console.error(error.message)
            res.status(500).send('Server Error')
        })
});
用户付款的过帐方法
router.post(
    '/payment/add',
    async (req, res) => {
        try {
            const user = await users.findById(req.user.id).select('-password');
            const { bankName, tranferRefCode, amount } = req.body;
            const newPayment = new UserWallet({
                bankName,
                tranferRefCode,
                amount,
                username: user.username,
                avatar: user.avatar,
                paymentBy: req.user.id
            });
            await newPayment.save().then(payment => {
                res.json({ newPayment: payment })
            })
        } catch (err) {
            console.error(err.message);
            res.status(500).send('Server Error');
        }
    }
);
用户付款方案
const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const walletSchema = new Schema({
    user: {
        type: Schema.Types.ObjectId,
        ref: 'user'
    },
    bankName: {
        type: String,
    },
    tranferRefCode: {
        type: String,
    },
    amount: {
        type: String,
    },
    username: {
        type: String
    },
    avatar: {
        type: String
    },
    date: {
        type: Date,
        default: Date.now
    }
})

module.exports = Wallet = mongoose.model('wallet', walletSchema)
付款结果加
{
    "newPayment": {
        "_id": "5ec0a61597d09440249a1dcc",
        "bankName": "sbi",
        "tranferRefCode": "kfjalskdfjkasdfjajs",
        "amount": "1000",
        "username": "s",
        "avatar": "https://gravatar.comxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx?d=mm&r=pg&s=200",
        "paymentBy": "5eb2fa29d37d9a08741621c8",
        "date": "2020-05-17T02:48:53.662Z",
        "__v": 0
    }
}
评论