node.js - mongoose dbref问题
PHPz
PHPz 2017-04-17 13:44:43
0
1
304
User.findOne({userid:account.user},function(err,docs){
    docs.accounts=account;
    User.findOne({}).populate('accounts').exec(function(err, doc){
         console.log('after populate: ', err, doc);
    });
});

我创建了一个用户表(字段:用户和密码,还有一个accounts字段连接后面的账单表)和一个账单表(用户和其他字段),
用户已经存在了,我存储账单表后,在用户表找到相应用户,在accounts字段存储对象,上面代码打印出来的却没有accounts这个字段,求大神解答谢谢哇!

PHPz
PHPz

学习是最好的投资!

reply all(1)
左手右手慢动作

A few questions:
1. populate in mongodb can only be associated with _id;
2. You foundOne and did not execute save after modifying it, so there is no modification in the database;
3. Since it is findOne, don’t use docs in the callback, there is ambiguity;
4. It is recommended to use findOneAndUpdate directly;

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template