0

I'm making a database for beavers, however some properties should be unchangeable such as the birth date or the location where it was first seen.

How do I implement this? Is there a mongoose schema property for this? Or do I do it with JS?

Example of the schema:

let beaverSchema = new Schema({
    id: {type: String, required: true, unique: true},
    birthDate: {type: Date},
    locationSpotted: {type: String},
    firstSeen: {type: Date},
    status: {type: String, default: "Alive"},
    sex: {type: String}
})
  • Not sure if this is possible to specify on the fields themselves without using a library like [mongoose-immutable](https://github.com/elbuo8/mongoose-immutable). But you can add a `pre('validate)` hook that disallows updating certain fields. Explanation in [this duplicate post](http://stackoverflow.com/questions/26342081/mongoose-disallow-updating-of-specific-fields) – the holla Feb 11 '17 at 08:27
  • Possible duplicate of [mongoose: disallow updating of specific fields](http://stackoverflow.com/questions/26342081/mongoose-disallow-updating-of-specific-fields) – the holla Feb 11 '17 at 08:28

0 Answers0