我的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
});
});
});
此代码似乎对象已更新。 return res.json({ 类型:true, 数据:商店 });
但是当我打开数据库或刷新页面时,我面对的是旧数据。
有什么问题?
更新:这是架构
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
}
});
答案 0 :(得分:0)
我开始使用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
}
});
现在保存多语言数据不是问题。