Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the Mongoose timestamps schema option indexed?

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?

like image 576
steampowered Avatar asked Aug 15 '16 21:08

steampowered


People also ask

What is timestamps in Mongoose schema?

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.

What is index in Mongoose schema?

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.

What does the schema do in Mongoose?

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 Mongoose schema type?

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.


1 Answers

No they are not indexed, You have to do indexing by yourself, like any other field.

animalSchema.index({"createdAt": 1});
animalSchema.index({"updatedAt": 1});
like image 192
enRaiser Avatar answered Oct 01 '22 06:10

enRaiser