如何使用Mongoose来(添加,更新,删除)嵌套文件

我是一个新鲜的mongoose用户,我有一个小的练习,我有这个模式

`var BusinessSchema = mongoose.Schema({ personal_email: { type: String, required: true, unique: true }, business_name: { type: String, required: true, unique: true }, business_emails: [{ email: String, Description: String }], business_logo: { data: Buffer, contentType: String }, //Business Services services: [{ service_name: { type:String,required:true}, service_price: Number, promotion_offer : Number, service_rating : [{Clinet_username:String ,rating : Number}], service_reviews : [{Clinet_username:String ,review : String}], type_flag : Boolean, available_flag : Boolean }] });` 

我想要做的是更新或添加新的服务或使用mongoose删除评级

 business.update({// something here to update service_rating },function(err,found_business) { }); business.update({// something here to add new service_rating },function(err,found_business) { }); business.update({// something here to delete service_rating },function(err,found_business) { }); 

var where_clause = { /* your where clause */ };
var service_rating = {"username", 5};

加上 :

 business.update(where_clause, { '$addToSet' : { services.service_rating : service_rating } }, callback); 

删除 :

 business.update(where_clause, { '$pull' : { services.service_rating : service_rating } }, callback); 

更新 :

var other_where = {services.service_rating : {"user", 5}}; // your where clause

 business.update(other_where, { '$set': { 'services.service_rating.Clinet_username' : 'newUser', 'services.service_rating.rating' : 10 } }, callback);