You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guide.md
+5Lines changed: 5 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1105,6 +1105,11 @@ to your schema. The type assigned is [Date](./api.html#schema-date-js).
1105
1105
By default, the names of the fields are `createdAt` and `updatedAt`. Customize
1106
1106
the field names by setting `timestamps.createdAt` and `timestamps.updatedAt`.
1107
1107
1108
+
The way `timestamps` works under the hood is:
1109
+
* If you create a new document, mongoose simply sets `createdAt`, and `updatedAt` to the time of creation.
1110
+
* If you update a document, mongoose will add `updatedAt` to the `$set` object.
1111
+
* If you set `upsert: true` on an update operation, mongoose will use [`$setOnInsert`](https://docs.mongodb.com/manual/reference/operator/update/setOnInsert/) operator to add `createdAt` to the document in case the `upsert` operation resulted into a new inserted document.
0 commit comments