I have the following schema:
const profileSchema = new Schema({
created: {
type: Date,
default: Date.now
},
readonly: {
type: Boolean,
default: false
}
});
const Profile = mongoose.model('profile',profileSchema);
However I have found that if I query for "date", the date is set on documents, but if I query for "readonly" it is NOT set to false, but will return false on the document. For example:
Profile.find({readonly: false})
Will return no documents. However, if I do:
Profile.find({})
I will receive all the documents and the property "readonly" will be listed as "false".
At the same time if when I create the document I do:
var newProfile = { readonly: false };
new Profile(newProfile).save();
The same find command above will list this document. It seems that the default for booleans is implicitly set and is available when the document is read, not queried. Is there a way to make sure it is set and findable on all documents just as the "created" date property is, or do I have to set it on all new documents manually?