Saturday 3 June 2017

Delete an array element from a document mongodb

I am having a schema called ReferralHistory. It contains set of users and array of referred users.

ReferralHistory

var mongoose = require('mongoose');
var refferalHistorySchema = new mongoose.Schema({
    user: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'User',
        unique: true
    },

    referrals: [{
        type: mongoose.Schema.Types.ObjectId,
        ref: 'User'
    }],
});
var ReferralHistoryModel = mongoose.model('ReferralHistory', refferalHistorySchema);
module.exports = {
    referralHistory: ReferralHistoryModel
}

I need to delete a particular user from referrals array in the collection ReferralHistory[Here i only know id of referred user].How can i achieve this?



via Muhsin

No comments:

Post a Comment