Mongoose version >= 4.0 has a timestamps option which creates an updatedAt
and createdAt
field for schemas when timestamps
is set to true
.
http://mongoosejs.com/docs/guide.html#timestamps
Are the updatedAt
and createdAt
fields indexed?
Mongoose timestamps are supported by the schema. Timestamps save the current time of the document created and also when it was updated in form of a Date by turning it true. When set to true, the mongoose creates two fields as follows: createdAt: Date representing when the document was created.
Indexes are defined through ensureIndex every time a model is compiled for a certain connection / database. This means that indexes will only be ensured once during the lifetime of your app.
A Mongoose schema defines the structure of the document, default values, validators, etc., whereas a Mongoose model provides an interface to the database for creating, querying, updating, deleting records, etc.
What is a SchemaType? You can think of a Mongoose schema as the configuration object for a Mongoose model. A SchemaType is then a configuration object for an individual property. A SchemaType says what type a given path should have, whether it has any getters/setters, and what values are valid for that path.
No they are not indexed, You have to do indexing by yourself, like any other field.
animalSchema.index({"createdAt": 1});
animalSchema.index({"updatedAt": 1});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With