So, there are two limits I want to set in mondo db:
1. Only allow one document to be inserted into the dbs, and no more. This document cannot be deleted once added, BUT it can be modified. Also, no other documents can be added to that collection.
Only one value will be allowed under this schema.
{ "_id" : ObjectId("5800"), "seconds" : "120", "__v" : 0 }
No more new seconds will be allowed to be added in, and only the above document can be modified.
I have tried:
var numbersSchema = new mongoose.Schema({
seconds: { type: Number, min: 60 }
},{ capped : true, size:4000, max : 1 })
However I can still add multiple documents:
{ "_id" : ObjectId("5800c7f53c609009dc5800f4"), "seconds" : 390, "__v" : 0 }
{ "_id" : ObjectId("5800c81b3c609009dc5800f5"), "seconds" : 590, "__v" : 0 }
2.Set a min value on a schema entry field.
var numbersSchema = new mongoose.Schema({
seconds: Number
})
So, in this case 'seconds' must be at least 60 seconds as the minimum value. I assume this needs to be changed in the schema, but I do not know how. Is it possible to add '>59' into the schema, or is there an option with mongo already?
Any tips would be appreciated!