Monday, 3 April 2017

how to use Mongoose to (add to , update,delete) Nested documents

I am a fresh mongoose user and I have a small exercise I have this schema

`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    
    }]
});`

what I want to do is to update or add new service or delete rating using 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)
          {
           });


via AmrAyman

No comments:

Post a Comment