MongoDB不会推送到数组

时间:2018-11-17 15:57:42

标签: node.js mongodb mongoose

我有一个唯一的功能是将对象推入mongodb中的数组。这不会推向阵列,但是,我也不知道为什么。 代码是:

itemfunctions.addItem = function(itemname, username) {
    User.findOne({username: username}, (err, user) => {
        if (user.inventory.length < 47) {
            return false;
        };
        var item = itemfunctions.itemInvTemplate; //{metadata: [], name: "", durability: null}
        var iteminfo = itemfunctions.getItem(itemname);
        item.name = itemname;
        item.durabilty = iteminfo.durability;
        User.findOneAndUpdate({username: username }, { $push: { inventory: item } },
            function (error, success) {
                if (error) {
                    console.log(error);
                }
                return true;
            });
    });
}

0 个答案:

没有答案