How to define a trigger in a mongoose circuit
is there any trigger at the mongoose model level that provides the ability to set the public field value = false when the number of member collections reaches 100?
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var listSchema = new Schema({
name: {
type: String,
required: true,
trim: true
},
desc: {
type: String
},
open: {
type: Boolean,
default: true
},
members: [{
userid: {
type: Schema.Types.ObjectId, ref: 'User'
},
prId: {
type: Schema.Types.ObjectId, ref: 'PR'
},
checkedIn: {
type: Boolean
}
}]
});
module.exports = mongoose.model('List', listSchema);
+3
source to share
1 answer
Triggers are not available in mongo. It's hard to say why you want to change documents when the collection reaches a certain limit, perhaps capped collection is what you really want?
new Schema({..}, { capped: { size: 1024, max: 100 } });
size is the maximum size of the collection in bytes, and max is the maximum number of documents that can be inserted into the collection.
+1
source to share