Skip to content

Latest commit

 

History

History
62 lines (47 loc) · 2.54 KB

metadata.md

File metadata and controls

62 lines (47 loc) · 2.54 KB
id title sidebar_label
metadata
Metadata
Metadata

Timestamps

rest-hapi supports the following optional timestamp metadata for documents:

When enabled, these properties will automatically be populated during CRUD operations. For example, say I create a user with a payload of:

 {
    "email": "test@email.com",
    "password": "1234"
 }

If I then query for this document I might get:

 {
    "_id": "588077dfe8b75a830dc53e8b",
    "email": "test@email.com",
    "createdAt": "2017-01-19T08:25:03.577Z"
 }

If I later update that user's email then an additional query might return:

 {
    "_id": "588077dfe8b75a830dc53e8b",
    "email": "test2@email.com",
    "createdAt": "2017-01-19T08:25:03.577Z",
    "updatedAt": "2017-01-19T08:30:46.676Z"
 }

The deletedAt property marks when a document was soft deleted.

NOTE: Timestamp metadata properties are only set/updated if the document is created/modified using rest-hapi endpoints/methods. Ex:

mongoose.model('user').findByIdAndUpdate(_id, payload) will not modify updatedAt whereas

RestHapi.update(mongoose.model('user'), _id, payload) will. (see Mongoose wrapper methods)

User tags

In addition to timestamps, the following user tag metadata can be added to a document:

If enabled, these properties will record the _id of the user performing the corresponding action.

This assumes that your authentication credentials (request.auth.credentials) will contain either a user object with a _id property, or the user's _id stored in a property defined by config.userIdKey.

NOTE: Unlike timestamp metadata, user tag properties are only set/updated if the document is created/modified using rest-hapi endpoints, (not rest-hapi methods).