{"id":16372537,"url":"https://github.com/dimadeveatii/mongo-dot-notation","last_synced_at":"2025-10-16T06:06:08.918Z","repository":{"id":36735793,"uuid":"41042388","full_name":"dimadeveatii/mongo-dot-notation","owner":"dimadeveatii","description":"Transform objects to MongoDB update instructions","archived":false,"fork":false,"pushed_at":"2024-03-29T22:13:39.000Z","size":207,"stargazers_count":51,"open_issues_count":1,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-11T07:38:42.516Z","etag":null,"topics":["dot-notation","mongo","mongo-dot-notation","mongo-operators","mongodb"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dimadeveatii.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE-OF-CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-08-19T15:23:15.000Z","updated_at":"2025-08-26T21:35:09.000Z","dependencies_parsed_at":"2024-06-18T15:49:30.540Z","dependency_job_id":"5aed23f3-60ab-4cf3-a51d-d6c47e670149","html_url":"https://github.com/dimadeveatii/mongo-dot-notation","commit_stats":{"total_commits":59,"total_committers":8,"mean_commits":7.375,"dds":"0.38983050847457623","last_synced_commit":"dc81d125e7ecb193395ce8e28c3ff289d708cda1"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/dimadeveatii/mongo-dot-notation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dimadeveatii%2Fmongo-dot-notation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dimadeveatii%2Fmongo-dot-notation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dimadeveatii%2Fmongo-dot-notation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dimadeveatii%2Fmongo-dot-notation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dimadeveatii","download_url":"https://codeload.github.com/dimadeveatii/mongo-dot-notation/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dimadeveatii%2Fmongo-dot-notation/sbom","scorecard":{"id":343131,"data":{"date":"2025-08-11","repo":{"name":"github.com/dimadeveatii/mongo-dot-notation","commit":"e4124cee6cc54c33f336397e9898e37de039be4e"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.8,"checks":[{"name":"Code-Review","score":0,"reason":"Found 0/22 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/ci.yml:1","Warn: no topLevel permission defined: .github/workflows/release.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":0,"reason":"Project has not signed or included provenance with any releases.","details":["Warn: release artifact release/v3.1.1 not signed: https://api.github.com/repos/dimadeveatii/mongo-dot-notation/releases/149064557","Warn: release artifact release/v3.1.0 not signed: https://api.github.com/repos/dimadeveatii/mongo-dot-notation/releases/73028323","Warn: release artifact release/v3.0.1 not signed: https://api.github.com/repos/dimadeveatii/mongo-dot-notation/releases/72824785","Warn: release artifact release/v3.1.1 does not have provenance: https://api.github.com/repos/dimadeveatii/mongo-dot-notation/releases/149064557","Warn: release artifact release/v3.1.0 does not have provenance: https://api.github.com/repos/dimadeveatii/mongo-dot-notation/releases/73028323","Warn: release artifact release/v3.0.1 does not have provenance: https://api.github.com/repos/dimadeveatii/mongo-dot-notation/releases/72824785"],"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Pinned-Dependencies","score":1,"reason":"dependency not pinned by hash detected -- score normalized to 1","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/dimadeveatii/mongo-dot-notation/ci.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/dimadeveatii/mongo-dot-notation/ci.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:45: update your workflow using https://app.stepsecurity.io/secureworkflow/dimadeveatii/mongo-dot-notation/ci.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/dimadeveatii/mongo-dot-notation/release.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/dimadeveatii/mongo-dot-notation/release.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:60: update your workflow using https://app.stepsecurity.io/secureworkflow/dimadeveatii/mongo-dot-notation/release.yml/main?enable=pin","Warn: containerImage not pinned by hash: Dockerfile:1: pin your Docker image by updating node:lts to node:lts@sha256:58a260471ff760412efdd89afb30d1518f94295a7a7f5e62d3f6e436735d27f9","Warn: npmCommand not pinned by hash: .github/workflows/ci.yml:27","Warn: npmCommand not pinned by hash: .github/workflows/release.yml:22","Info:   0 out of   4 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   2 third-party GitHubAction dependencies pinned","Info:   0 out of   1 containerImage dependencies pinned","Info:   1 out of   3 npmCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'main'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 11 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":5,"reason":"5 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-18T06:25:24.022Z","repository_id":36735793,"created_at":"2025-08-18T06:25:24.022Z","updated_at":"2025-08-18T06:25:24.022Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279161563,"owners_count":26116985,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-16T02:00:06.019Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dot-notation","mongo","mongo-dot-notation","mongo-operators","mongodb"],"created_at":"2024-10-11T03:11:41.505Z","updated_at":"2025-10-16T06:06:08.900Z","avatar_url":"https://github.com/dimadeveatii.png","language":"TypeScript","readme":"# mongo-dot-notation\n\nTransform objects to MongoDB update instructions.\n\n[![Build status](https://github.com/dimadeveatii/mongo-dot-notation/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/dimadeveatii/mongo-dot-notation/actions/workflows/ci.yml?query=branch%3Amain++)\n[![Coverage Status](https://coveralls.io/repos/github/dimadeveatii/mongo-dot-notation/badge.svg?branch=main)](https://coveralls.io/github/dimadeveatii/mongo-dot-notation?branch=main)\n[![NPM Version](https://img.shields.io/npm/v/mongo-dot-notation.svg)](https://npmjs.org/package/mongo-dot-notation)\n[![Downloads](https://img.shields.io/npm/dm/mongo-dot-notation)](https://npmjs.org/package/mongo-dot-notation)\n\n```ts\nimport { flatten, $timestamp, $unset } from 'mongo-dot-notation';\n\nconst user = flatten({\n  firstName: 'Alice',\n  contact: { phone: '874-478-1254' },\n  address: {\n    primary: {\n      state: 'NY',\n      nr: 42,\n    },\n  },\n});\n```\n\nSets `user` to:\n\n```json\n{\n  \"$set\": {\n    \"firstName\": \"Alice\",\n    \"contact.phone\": \"874-478-1254\",\n    \"address.primary.state\": \"NY\",\n    \"address.primary.nr\": 42\n  }\n}\n```\n\n## Installation\n\n```sh\nnpm install mongo-dot-notation\n```\n\n## Highlights\n\n- Supports all MongoDB [update operators](https://www.mongodb.com/docs/manual/reference/operator/update/)\n  - Field update operators\n  - Array update operators\n  - Bitwise update operators\n- No `npm` dependency on `mongo`\n- Written in TypeScript\n  - Type definitions for all exported functions\n- Supports flattening and updating array elements by index\n\n## Usage and examples\n\n### Using operators to update fields\n\n```ts\nimport { flatten, $inc, $currentDate, $push, $setOnInsert } from 'mongo-dot-notation';\n\nconst review = {\n  // Add a comment and keep only the last ten ones\n  comments: $push('Like it!').$each().$slice(-10),\n  rating: 10,\n  counters: {\n    // increment the `total` by one\n    total: $inc(),\n  },\n  details: {\n    // set only if the document is inserted\n    createdOn: $setOnInsert(new Date()),\n    // set to current date as a mongo Date\n    updatedOn: $currentDate(),\n  },\n};\n\n// Provided reviews is a MongoDB collection\nawait reviews.updateOne(reviewId, flatten(review), { upsert: true });\n```\n\n### Flattening arrays\n\n```ts\nimport { flatten } from 'mongo-dot-notation';\n\nconst user = {\n  phones: [\n    {\n      number: '123-456-789',\n      primary: true,\n    },\n    {\n      number: '789-012-345',\n    },\n  ],\n};\n\n// Provided users is a MongoDB collection\nawait users.updateOne(userId, flatten(user, { array: true }));\n```\n\nThe above `user` object is flattened to:\n\n```json\n{\n  \"phones.0.number\": \"123-456-789\",\n  \"phones.0.primary\": true,\n  \"phones.1.number\": \"789-012-345\"\n}\n```\n\n### Using positional operator\n\n```ts\nimport { flatten, $, $inc } from 'mongo-dot-notation';\n\nconst student = {\n  grades: $().$inc(),\n};\n\n// Finds the element with value 80 in the \"grades\" array\n// and increments it by one.\nstudent.updateOne(\n  { _id: 1, grades: 80 },\n  flatten(student) // { $inc: { \"grades.$\" : 1 } }\n);\n```\n\nThe position operator supports updating a nested document:\n\n```ts\nimport { flatten, $, $inc } from 'mongo-dot-notation';\n\nconst student = {\n  grades: $('value').$inc(),\n};\n\n// Finds the document with \"value\" field equal to 80 in the \"grades\" array\n// and increments it by one.\nstudent.updateOne(\n  { _id: 1, grades: 80 },\n  flatten(student) // { $inc: { \"grades.$.value\" : 1 } }\n);\n```\n\nTo update all elements in a array, use _all positional_ operator:\n\n```ts\nimport { flatten, $, $inc } from 'mongo-dot-notation';\n\nconst student = {\n  grades: $('[]').$inc(),\n};\n\n// Increment all grades by one\nstudent.updateOne(\n  { _id: 1 },\n  flatten(student) // { $inc: { \"grades.$[]\" : 1 } }\n);\n```\n\nSimilarly, updating nested documents:\n\n```ts\nimport { flatten, $, $inc } from 'mongo-dot-notation';\n\nconst student = {\n  grades: $('[].values').$inc(),\n};\n\n// Increment all grades' values by one\nstudent.updateOne(\n  { _id: 1 },\n  flatten(student) // { $inc: { \"grades.$[].values\" : 1 } }\n);\n```\n\n### Using filtered positional operator\n\n```ts\nimport { flatten, $, $mul } from 'mongo-dot-notation';\n\nconst student = {\n  grades: $('[element]').$mul(9),\n};\n\n// Multiply by ten all grades that are below 9\nstudent.updateOne(\n  { _id: 1 },\n  flatten(student), // { $mul: { \"grades.$[element]\" : 10 } }\n  { arrayFilters: [{ element: { $lte: 9 } }] }\n);\n```\n\nSimilarly, updating nested documents:\n\n```ts\nimport { flatten, $, $mul } from 'mongo-dot-notation';\n\nconst student = {\n  grades: $('[element].value').$mul(9),\n};\n\n// Multiply by ten all grades that are below 9\nstudent.updateOne(\n  { _id: 1 },\n  flatten(student), // { $mul: { \"grades.$[element].value\" : 10 } }\n  { arrayFilters: [{ 'element.value': { $lte: 9 } }] }\n);\n```\n\n### Merge array documents\n\nUsing positional operator to merge fields into the matched element:\n\n```ts\nimport { flatten, $, $inc, $currentDate } from 'mongo-dot-notation';\n\nconst student = {\n  grades: $().merge({\n    class: '101',\n    prof: 'Alice',\n    value: $inc(),\n    date: $currentDate(),\n  }),\n};\n\nflatten(student);\n```\n\nResult:\n\n```json\n{\n  \"$set\": {\n    \"grades.$.class\": \"101\",\n    \"grades.$.prof\": \"Alice\"\n  },\n  \"$inc\": {\n    \"grades.$.value\": 1\n  },\n  \"$currentDate\": {\n    \"grades.$.date\": { \"$type\": \"date\" }\n  }\n}\n```\n\nTo update all elements, use `$('[]')` instead of `$()` in the above example.\n\n### Update nested arrays\n\nUsing positional operator to update nested arrays:\n\n```ts\nimport { flatten, $, $mul } from 'mongo-dot-notation';\n\nconst student = {\n  grades: $().merge({\n    questions: $('[]').merge({\n      value: $mul(100),\n    }),\n  }),\n};\n\nflatten(student);\n```\n\nCalling `flatten(student)` results in:\n\n```json\n{\n  \"$mul\": {\n    \"grades.$.questions.$[].value\": 100\n  }\n}\n```\n\nSee the [end-to-end](tests/mongo.e2e.ts) tests file for more examples.\n\n## API\n\n**Table of contents**\n\n- [Options](#options)\n- [flatten](#flatten)\n- [isOperator](#isOperator)\n\n- [Field update operators](#field-update-operators)\n\n  - [$currentDate](#currentdate)\n  - [$timestamp](#timestamp)\n  - [$inc](#inc)\n  - [$min](#min)\n  - [$max](#max)\n  - [$mul](#mul)\n  - [$rename](#rename)\n  - [$set](#set)\n  - [$setOnInsert](#setoninsert)\n  - [$unset](#unset)\n\n- [Array update operators](#array-update-operators)\n\n  - [$](#-positional)\n  - [$addToSet](#addtoset)\n  - [$pop](#pop)\n  - [$pull](#pull)\n  - [$push](#push)\n  - [$pullAll](#pullall)\n  - [$slice](#slice)\n  - [$sort](#sort)\n\n- [Bitwise update operators](#bitwise-update-operators)\n\n  - [$bit](#bit)\n  - [$and](#and)\n  - [$or](#or)\n  - [$xor](#xor)\n\n### Options\n\nThe following options are available:\n\n| Option             | Description                                                                                   |\n| ------------------ | --------------------------------------------------------------------------------------------- |\n| `array`            | _(default `false`)_ if true, arrays will be flattened and their indexes will be used as keys. |\n| `skipEmptyObjects` | _(default `false`)_ if true, empty objects are ignored and removed from the flattened result. |\n\n**Example:**\n\n```ts\nflatten({ rules: [{ value: 7 }] }, { array: true });\n// { $set: { 'rules.0.value': 7 } }\n\nflatten({ rules: [{ value: 7 }] }, { array: false });\n// { $set: { 'rules': [{value: 7}] } }\n\nflatten({ left: { x: 1 }, right: {} }, { skipEmptyObjects: true });\n// { $set: { 'left.x': 1 } }\n\nflatten({ left: { x: 1 }, right: {} }, { skipEmptyObjects: false });\n// { $set: { 'left.x': 1, 'right': {} } }\n```\n\n### flatten\n\n\u003e `$flatten\u003cT\u003e(obj: T, options?: Options)`\n\nTransforms a given object into the MongoDB's update instructions.\n\n| Param     | Description                                              |\n| --------- | -------------------------------------------------------- |\n| `obj`     | _(required)_ the input object to transform               |\n| `options` | _(optional)_ additional options, see [Options](#options) |\n\n**Example:**\n\n```ts\nflatten({\n  firstName: 'Alice',\n  contact: { phone: '874-478-1254' },\n  address: {\n    primary: {\n      state: 'NY',\n      nr: 42,\n    },\n  },\n});\n```\n\n### isOperator\n\n\u003e `isOperator\u003cT\u003e(obj: T): boolean`\n\nChecks if a given object is an operator.\n\n| Param | Description                            |\n| ----- | -------------------------------------- |\n| `obj` | _(required)_ the input object to check |\n\n**Example:**\n\n```ts\nisOperator($set(1)); // true\nisOperator({}); // false\n```\n\n---\n\n### Field update operators\n\n### $currentDate\n\n\u003e `$currentDate(type?: 'date' | 'timestamp')`\n\n| Param  | Description                                                                                                                                                                                                                                                     |\n| ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `type` | _(default `date`)_ sets to MongoDB's [Date](https://www.mongodb.com/docs/manual/reference/bson-types/#std-label-document-bson-type-date) or [Timestamp](https://www.mongodb.com/docs/manual/reference/bson-types/#std-label-document-bson-type-timestamp) type. |\n\nSets the value of a field to the current date.\n\n**Example:**\n\n```ts\nflatten({\n  createdOn: $currentDate(),\n});\n```\n\n[MongoDB manual](https://www.mongodb.com/docs/manual/reference/operator/update/currentDate/)\n\n### $timestamp\n\n\u003e `$timestamp()`\n\nSets 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.\n\nThis function is an alias for `$currentDate('timestamp')`.\n\n**Example:**\n\n```ts\nflatten({\n  updatedOn: $timestamp(),\n});\n```\n\n[MongoDB manual](https://www.mongodb.com/docs/manual/reference/operator/update/currentDate/)\n\n### $inc\n\n\u003e `$inc\u003cT\u003e(value?: T)`\n\nIncrements a field by a specified value.\n\n| Param   | Description                   |\n| ------- | ----------------------------- |\n| `value` | _(default 1)_ increment value |\n\n**Example:**\n\n```ts\nflatten({\n  visits: $inc(),\n  clicks: $inc(5),\n});\n```\n\n[MongoDB manual](https://www.mongodb.com/docs/manual/reference/operator/update/inc/)\n\n### $min\n\n\u003e `$min\u003cT\u003e(value: T)`\n\nUpdates the value of the field to a specified value if the specified value is **less than** the current value of the field.\n\n| Param   | Description            |\n| ------- | ---------------------- |\n| `value` | _(required)_ min value |\n\n**Example:**\n\n```ts\nflatten({\n  score: $min(100),\n});\n```\n\n[MongoDB manual](https://www.mongodb.com/docs/manual/reference/operator/update/min/)\n\n### $max\n\n\u003e `$max\u003cT\u003e(value: T)`\n\nUpdates the value of the field to a specified value if the specified value is **greater than** the current value of the field.\n\n| Param   | Description            |\n| ------- | ---------------------- |\n| `value` | _(required)_ max value |\n\n**Example:**\n\n```ts\nflatten({\n  score: $max(0),\n});\n```\n\n[MongoDB manual](https://www.mongodb.com/docs/manual/reference/operator/update/max/)\n\n### $mul\n\n\u003e `$mul\u003cT\u003e(value?: T)`\n\nMultiplies the value of a field by a number.\n\n| Param   | Description                   |\n| ------- | ----------------------------- |\n| `value` | _(default 1)_ multiply factor |\n\n**Example:**\n\n```ts\nflatten({\n  score: $mul(2.5),\n});\n```\n\n[MongoDB manual](https://www.mongodb.com/docs/manual/reference/operator/update/max/)\n\n### $rename\n\n\u003e `$rename(field: string)`\n\nUpdates the name of a field.\n\n| Param   | Description                 |\n| ------- | --------------------------- |\n| `field` | _(required)_ new field name |\n\n**Example:**\n\n```ts\nflatten({\n  profile: {\n    first_name: $rename('firstName'),\n  },\n});\n```\n\n[MongoDB manual](https://www.mongodb.com/docs/manual/reference/operator/update/rename/)\n\n### $set\n\n\u003e `$set\u003cT\u003e(value: T)`\n\nReplaces the value of a field with the specified value.  \nThis is an implicit operator, but could be useful when an entire object should be replaced.\n\n| Param   | Description                    |\n| ------- | ------------------------------ |\n| `value` | _(required)_ replacement value |\n\n**Example:**\n\n```ts\n// Replaces the address object entirely rather than just\n// updating the \"city\" field.\nflatten({\n  address: $set({ city: 'NY' }),\n  profile: { name: 'Alice' },\n});\n\n// Outputs:\n// {\n//   \"$set\": {\n//     \"address\": { \"city\": \"NY\" },\n//     \"profile.name\": \"Alice\"\n//   }\n// }\n```\n\n[MongoDB manual](https://www.mongodb.com/docs/manual/reference/operator/update/set/)\n\n### $setOnInsert\n\n\u003e `$setOnInsert\u003cT\u003e(value: T)`\n\nAssigns the specified value to the field when `{ upsert: true }` operation is used and\nresults in a new document being created. If the update operation does not result in an insert,\ndoes nothing.\n\n| Param   | Description                                        |\n| ------- | -------------------------------------------------- |\n| `value` | _(required)_ the value to set on document creation |\n\n**Example:**\n\n```ts\nflatten({\n  logging: {\n    createdOn: $setOnInsert(new Date()),\n  },\n});\n```\n\n[MongoDB manual](https://www.mongodb.com/docs/manual/reference/operator/update/setOnInsert/)\n\n### $unset\n\n\u003e `$unset()`\n\nDeletes the specified field from a document.\n\n**Example:**\n\n```ts\nflatten({\n  resetPassword: $unset(),\n});\n```\n\n[MongoDB manual](https://www.mongodb.com/docs/manual/reference/operator/update/unset/)\n\n---\n\n### Array update operators\n\n### $ _(positional)_\n\n\u003e `$(field?: number | string)`\n\nThe positional operator identifies **an element** or **multiple elements** matching a\ngiven query condition to be updated in an array.\n\n| Param   | Description                                                                                                                                                                                                                                                                          |\n| ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |\n| `field` | _(optional)_ when empty - performs the update on array's element; \u003cbr/\u003ewhen a number or a string starting with a number, specifies the index of the element to update or its field;\u003cbr/\u003ewhen starts with `\"[]\"` or `\"[query]\"`, specifies that this is an _all positional_ operator; |\n\n**Example:**\n\n```ts\n// Sets to 7 first element that matches the update query\n$().$set(7);\n\n// Increment by one the first element's `score` field that matches the update query\n$('score').$inc(1);\n\n// Multiplies all elements by two\n$('[]').$mul(2);\n\n// Ensures all elements in array are positive\n$('[].score').$max(0);\n\n// Find all `grades` documents that have the `std` lower than seven\n// and increment their `grade` by ten.\ncollection.updateOne(criteria, flatten({ grades: $('[element].grade').$inc(10) }), {\n  arrayFilters: [{ 'element.std': { $lt: 7 } }],\n});\n```\n\nSee [update nested arrays](#update-nested-arrays) for examples using `$().merge`.\n\n[MongoDB manual](https://www.mongodb.com/docs/manual/reference/operator/update/positional/)\n\n### $addToSet\n\n\u003e `$addToSet\u003cT\u003e(value: T | T[])`\n\nAdds a value to an array unless the value is already present.\nTo add multiple values, chain with `$each` operator.\n\n| Param   | Description                              |\n| ------- | ---------------------------------------- |\n| `value` | _(required)_ the value to add to the set |\n\nNote that while `$addToSet([1, 2])` adds the entire array as single element,\n`$addToSet([1, 2]).$each()` adds 1 and 2 as separate elements.\n\n**Example:**\n\n```ts\n// add just one element\nflatten({ permissions: $addToSet('admin') });\n\n// add multiple elements\nflatten({ permissions: $addToSet(['read', 'write']).$each() });\n```\n\n[MongoDB manual](https://www.mongodb.com/docs/manual/reference/operator/update/addToSet/)\n\n### $pop\n\n\u003e `$pop(value?: -1 | 1)`\n\nRemoves the first or last element of an array\n\n| Param   | Description                                                                            |\n| ------- | -------------------------------------------------------------------------------------- |\n| `value` | _(default 1)_ specify `-1` to remove the first element, `1` to remove the last element |\n\n**Example:**\n\n```ts\n// remove the first element from the array\nflatten({ grades: $pop(-1) });\n// equivalent to:\nflatten({ grades: $pop().first() });\n\n// remove the last element from the array\nflatten({ scores: $pop(1) });\n// equivalent to:\nflatten({ scores: $pop().last() });\n```\n\n[MongoDB manual](https://www.mongodb.com/docs/manual/reference/operator/update/pop/)\n\n### $pull\n\n\u003e `$pull\u003cT\u003e(value: T | T[])`\n\nRemoves from an existing array all instances of a value or values that match a specified condition.\nUnlike the [$pullAll](#pullall) operator, this operator can be used to remove all instances that match a query.\n\n| Param   | Description                                                                        |\n| ------- | ---------------------------------------------------------------------------------- |\n| `value` | _(required)_ the value(s) to remove or the condition to match for removed elements |\n\n**Example:**\n\n```ts\n// remove all instances of the value `0` and `1` from the array;\n// same as using $pullAll\nflatten({ scores: $pull([0, 1]) });\n\n// remove all instances lower than or equal to `3`\nflatten({ scores: $pull({ $lte: 3 }) });\n\n// remove all documents with the field `name` equal to `Test`\nflatten({ users: $pull({ name: { $eq: 'Test' } }) });\n```\n\n[MongoDB manual](https://www.mongodb.com/docs/manual/reference/operator/update/pull/)\n\n### $push\n\n\u003e `$push\u003cT\u003e(value?: T | T[])`\n\nAppends a specified value to an array.\nCan be chained with `.$slice()`, `.$sort()` and `.$position()` modifiers to specify how the array should be updated.  \nThe order in which additional operators are chained doesn't matter, so that `$push().$each().$slice().$sort()` is the same as\n`$push().$each().$sort().$slice()`.\n\n| Param   | Description                                      |\n| ------- | ------------------------------------------------ |\n| `value` | _(optional)_ the value(s) to append to the array |\n\n**Example:**\n\n```ts\n// append one element\nflatten({ scores: $push(1) });\n\n// append multiple elements\nflatten({ scores: $push([1, 2, 3]).$each() });\n\n// append an element and update to leave only the last ten\nflatten({ scores: $push(7).$each().$slice(-10) });\n\n// append an element and update to leave only the last ten sorted by value\nflatten({ scores: $push(7).$each().$sort(1).$slice(-10) });\n\n// append an element at position three in the array\nflatten({ scores: $push(7).$each().$position(2) });\n```\n\n[MongoDB manual](https://www.mongodb.com/docs/manual/reference/operator/update/push/)\n\n### $pullAll\n\n\u003e `$pullAll\u003cT\u003e(value: T | T[])`\n\nRemoves all instances of the specified values from an existing array.\n\n| Param   | Description                                        |\n| ------- | -------------------------------------------------- |\n| `value` | _(required)_ the value(s) to remove from the array |\n\n**Example:**\n\n```ts\n// remove all instances of the value `1` and `2` from the array\nflatten({ score: $pullAll([1, 2]) });\n\n// remove all instances of the value `0`\nflatten({ score: $pullAll(0) });\n```\n\n[MongoDB manual](https://www.mongodb.com/docs/manual/reference/operator/update/pullAll/)\n\n### $slice\n\n\u003e `$slice(count: number)`\n\nLimits the number of array elements.\nAlias for `$push().$each().$slice()`.\n\n| Param   | Description                             |\n| ------- | --------------------------------------- |\n| `count` | _(required)_ number of elements to take |\n\n**Example:**\n\n```ts\n// leave only the first 3 elements\nflatten({ grades: $slice(3) });\n\n// leave only the last element\nflatten({ grades: $slice(-1) });\n\n// empty the array\nflatten({ grades: $slice(0) });\n```\n\n[MongoDB manual](https://www.mongodb.com/docs/manual/reference/operator/update/slice/)\n\n### $sort\n\n\u003e `$sort\u003cT\u003e(specification?: T)`\n\nOrders the elements of an array.\nAlias for `$push().$each().$sort()`.\n\n| Param           | Description                      |\n| --------------- | -------------------------------- |\n| `specification` | _(default 1)_ sort specification |\n\n**Example:**\n\n```ts\n// sort ascending\nflatten({ scores: $sort(1) });\n\n// sort descending\nflatten({ scores: $sort(-1) });\n\n// sort ascending an array of documents with `name` field\nflatten({ users: $sort({ name: 1 }) });\n```\n\n[MongoDB manual](https://www.mongodb.com/docs/manual/reference/operator/update/sort/)\n\n---\n\n### Bitwise update operators\n\n### $bit\n\n\u003e `$bit()`\n\nPerforms a bitwise update of a field.\nShould be chained with a logical operator.\n\n**Example:**\n\n```ts\nflatten({\n  admin: $bit().$and(7),\n  read: $bit().$or(4),\n  write: $bit().$xor(3),\n});\n```\n\n[MongoDB manual](https://www.mongodb.com/docs/manual/reference/operator/update/bit/)\n\n### $and\n\n\u003e `$and\u003cT\u003e(value: T)`\n\nUses a bitwise _and_ operation to update a field.\nAlias for `$bit().$and()`.\n\n**Example:**\n\n```ts\nflatten({\n  admin: $and(7),\n});\n```\n\n[MongoDB manual](https://www.mongodb.com/docs/manual/reference/operator/update/bit/#bitwise-and)\n\n### $or\n\n\u003e `$or\u003cT\u003e(value: T)`\n\nUses a bitwise _or_ operation to update a field.\nAlias for `$bit().$or()`.\n\n**Example:**\n\n```ts\nflatten({\n  read: $or(4),\n});\n```\n\n[MongoDB manual](https://www.mongodb.com/docs/manual/reference/operator/update/bit/#bitwise-or)\n\n### $xor\n\n\u003e `$xor\u003cT\u003e(value: T)`\n\nUses a bitwise _xor_ operation to update a field.\nAlias for `$bit().$xor()`.\n\n**Example:**\n\n```ts\nflatten({\n  write: $xor(3),\n});\n```\n\n[MongoDB manual](https://www.mongodb.com/docs/manual/reference/operator/update/bit/#bitwise-xor)\n\n## License\n\n[MIT](LICENSE)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdimadeveatii%2Fmongo-dot-notation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdimadeveatii%2Fmongo-dot-notation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdimadeveatii%2Fmongo-dot-notation/lists"}