UNPKG

mongo-dot-notation

Version:
78 lines (77 loc) 3.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.$timestamp = exports.$currentDate = exports.$unset = exports.$setOnInsert = exports.$rename = exports.$mul = exports.$min = exports.$max = exports.$inc = exports.$set = void 0; const operator_1 = require("./operator"); /** * Replaces the value of a field with the specified value. * @param value replacement value * @see https://www.mongodb.com/docs/manual/reference/operator/update/set/ */ const $set = (value) => (0, operator_1.create)('$set', value); exports.$set = $set; /** * Increments a field by a specified value. * @param value amount to increment by (default `1`) * @see https://www.mongodb.com/docs/manual/reference/operator/update/inc/ */ const $inc = (value) => (0, operator_1.create)('$inc', value !== null && value !== void 0 ? value : 1); exports.$inc = $inc; /** * Updates the value of the field to a specified value if the specified value is **greater than** * the current value of the field. * @param value max value * @see https://www.mongodb.com/docs/manual/reference/operator/update/max/ */ const $max = (value) => (0, operator_1.create)('$max', value); exports.$max = $max; /** * Updates the value of the field to a specified value if the specified value is **less than** * the current value of the field. * @param value min value * @see https://www.mongodb.com/docs/manual/reference/operator/update/min/ */ const $min = (value) => (0, operator_1.create)('$min', value); exports.$min = $min; /** * Multiplies the value of a field by a number. * @param value multiply factor (default `1`) * @see https://www.mongodb.com/docs/manual/reference/operator/update/mul/ */ const $mul = (value) => (0, operator_1.create)('$mul', value !== null && value !== void 0 ? value : 1); exports.$mul = $mul; /** * Updates the name of a field. * @param field new field name * @see https://www.mongodb.com/docs/manual/reference/operator/update/rename/ */ const $rename = (field) => (0, operator_1.create)('$rename', field); exports.$rename = $rename; /** * Assigns the specified value to the field when `{ upsert: true }` operation is used and * results in a new document being created. If the update operation does not result in an insert, * does nothing. * @param value the value to set on document creation * @see https://www.mongodb.com/docs/manual/reference/operator/update/setOnInsert/ */ const $setOnInsert = (value) => (0, operator_1.create)('$setOnInsert', value); exports.$setOnInsert = $setOnInsert; /** * Deletes the specified field from a document. * @see https://www.mongodb.com/docs/manual/reference/operator/update/unset/ */ const $unset = () => (0, operator_1.create)('$unset', ''); exports.$unset = $unset; /** * Sets the value of a field to the current date. * @param type (default `date`) when `date` is used sets to MongoDB's [Date](https://www.mongodb.com/docs/manual/reference/bson-types/#std-label-document-bson-type-date) type, for `timestamp` sets to [Timestamp](https://www.mongodb.com/docs/manual/reference/bson-types/#std-label-document-bson-type-timestamp). * @see https://www.mongodb.com/docs/manual/reference/operator/update/currentDate/ */ const $currentDate = (type = 'date') => (0, operator_1.create)('$currentDate', { $type: type }); exports.$currentDate = $currentDate; /** * Sets the value of a field to the current date as a MondoDB's [Timestamp](https://www.mongodb.com/docs/manual/reference/bson-types/#std-label-document-bson-type-timestamp) type. * This is an alias for `$currentDate('timestamp')`. * @see https://www.mongodb.com/docs/manual/reference/operator/update/currentDate/ */ const $timestamp = () => (0, exports.$currentDate)('timestamp'); exports.$timestamp = $timestamp;