Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Mongoosejs更新文档似乎有效,但实际上无效_Node.js_Mongoose - Fatal编程技术网

Node.js Mongoosejs更新文档似乎有效,但实际上无效

Node.js Mongoosejs更新文档似乎有效,但实际上无效,node.js,mongoose,Node.js,Mongoose,我的NodeJS服务器中有以下代码: Shop.findById(req.params.shopid, function(err, shop) { if (err) return res.json(err); shop.name = _.extend(shop.name, req.body.name); shop.description = _.extend(shop.description, req.body.description); shop.social

我的NodeJS服务器中有以下代码:

Shop.findById(req.params.shopid, function(err, shop) {
    if (err) return res.json(err);
    shop.name = _.extend(shop.name, req.body.name);
    shop.description = _.extend(shop.description, req.body.description);
    shop.social = _.extend(shop.social, req.body.social);
    shop.save(function(err) {
        if (err) return res.json(err);
        return res.json({
            type: true,
            data: shop
        });
    });
});
这段代码看起来像是对象被更新了。 返回res.json({ 类型:对, 资料来源:商店 });

但当我打开数据库或刷新页面时,我面对的是旧数据

有什么问题

更新:这里是模式

var ShopSchema = new Schema({
name: {
    type: Schema.Types.Mixed,
    default: {}
},
description: {
    type: Schema.Types.Mixed,
    default: {}
},
code: {
    type: String,
    default: shortId.generate()
},
pincode: {
    type: String,
    default: generatePassword(4, false, /\d/)
},
locale: String,
createdAt: {
    type: Date,
    default: Date.now
},
defaultLanguage: {
    type: Schema.ObjectId,
    ref: 'Language'
},
languages: [{
    type: Schema.ObjectId,
    ref: 'Language'
}],
account: {
    type: Schema.ObjectId,
    ref: 'Account'
},
social: {
    facebook: String,
    twitter: String,
    instagram: String,
    foursquare: String,
    website: String
},
images: {
    homepage: String,
    background: String,
    logo: String
},

address: {
    city: String,
    state: String,
    country: String,
    phone: String,
    email: String
}
});

我开始使用mongoose-i18n插件

var ShopSchema = new Schema({
name: {
    i18n: true,
    type: String
},
description: {
    i18n: true,
    type: String
},
code: {
    type: String,
    default: shortId.generate()
},
pincode: {
    type: String,
    default: generatePassword(4, false, /\d/)
},
locale: String,
createdAt: {
    type: Date,
    default: Date.now
},
defaultLanguage: {
    type: Schema.ObjectId,
    ref: 'Language'
},
languages: [{
    type: Schema.ObjectId,
    ref: 'Language'
}],
account: {
    type: Schema.ObjectId,
    ref: 'Account'
},
social: {
    facebook: String,
    twitter: String,
    instagram: String,
    foursquare: String,
    website: String
},
images: {
    homepage: String,
    background: String,
    logo: String
},

address: {
    city: String,
    state: String,
    country: String,
    phone: String,
    email: String
}
});

保存多语言数据现在不是问题。

启用mongoose调试并查看控制台。每个字段的数据类型是什么?如果它们是数组,mongoose要求您设置
markModified
,以便进行db写入。您的响应只是返回您正在创建的对象,而不是回调返回的对象,这就是它“看起来”正常工作的原因。您可以发布模式吗?