【发布时间】:2014-06-27 11:24:37
【问题描述】:
我试图简单地在猫鼬中增加一个对象的值,它似乎不想超过 2?有什么我想念的吗?我对 Mongo 还很陌生
campsite.findOne({slug : req.body.campsite.slug }, function(err, site){
if(!site.tracking){
console.log("no previous tracking at all");
site.tracking = {};
}
if(site.tracking[req.body.tracking_type] == undefined){
console.log("no previous tracking of this type");
site.tracking[req.body.tracking_type] = 1;
}else{
console.log("well count it then!");
site.tracking[req.body.tracking_type] += + 1;
}
site.save(function (err, fluffy) {
console.log(err);
});
res.send(200);
});
它只是不会保存更新的结果?我的架构在下面
var campsitesSchema = new Schema({
name: String,
address_line_1: String,
address_line_2: String,
county: String,
postcode: String,
loc: Array,
website: String,
email: String,
telephone_1: String,
telephone_2: String,
description: String,
slug:String,
status:String,
confirm_url_key: String,
password: String,
short_description: String,
long_description: String,
features: Array,
tracking: {}
});
【问题讨论】: