[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-10148":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":17,"stars30d":18,"stars90d":16,"forks30d":16,"starsTrendScore":16,"compositeScore":19,"rankGlobal":10,"rankLanguage":10,"license":20,"archived":21,"fork":21,"defaultBranch":22,"hasWiki":21,"hasPages":23,"topics":24,"createdAt":10,"pushedAt":10,"updatedAt":29,"readmeContent":30,"aiSummary":31,"trendingCount":16,"starSnapshotCount":16,"syncStatus":32,"lastSyncTime":33,"discoverSource":34},10148,"node-mongodb-native","mongodb\u002Fnode-mongodb-native","mongodb","The official MongoDB Node.js driver","https:\u002F\u002Fwww.mongodb.com\u002Fdocs\u002Fdrivers\u002Fnode\u002Fcurrent\u002F",null,"TypeScript",10179,1818,250,31,0,1,9,71.18,"Apache License 2.0",false,"main",true,[25,7,26,27,28],"database","node-js","nodejs","nosql","2026-06-12 04:00:48","# MongoDB Node.js Driver\n\nThe official [MongoDB](https:\u002F\u002Fwww.mongodb.com\u002F) driver for Node.js.\n\n**Upgrading to version 7? Take a look at our [upgrade guide here](https:\u002F\u002Fgithub.com\u002Fmongodb\u002Fnode-mongodb-native\u002Fblob\u002FHEAD\u002Fetc\u002Fnotes\u002FCHANGES_7.0.0.md)!**\n\n## Quick Links\n\n| Site                     | Link                                                                                                                                  |\n| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------- |\n| Documentation            | [www.mongodb.com\u002Fdocs\u002Fdrivers\u002Fnode](https:\u002F\u002Fwww.mongodb.com\u002Fdocs\u002Fdrivers\u002Fnode)                                                        |\n| API Docs                 | [mongodb.github.io\u002Fnode-mongodb-native](https:\u002F\u002Fmongodb.github.io\u002Fnode-mongodb-native)                                                |\n| `npm` package            | [www.npmjs.com\u002Fpackage\u002Fmongodb](https:\u002F\u002Fwww.npmjs.com\u002Fpackage\u002Fmongodb)                                                                |\n| MongoDB                  | [www.mongodb.com](https:\u002F\u002Fwww.mongodb.com)                                                                                            |\n| MongoDB University       | [learn.mongodb.com](https:\u002F\u002Flearn.mongodb.com\u002Fcatalog?labels=%5B%22Language%22%5D&values=%5B%22Node.js%22%5D)                         |\n| MongoDB Developer Center | [www.mongodb.com\u002Fdeveloper](https:\u002F\u002Fwww.mongodb.com\u002Fdeveloper\u002Flanguages\u002Fjavascript\u002F)                                                  |\n| Stack Overflow           | [stackoverflow.com](https:\u002F\u002Fstackoverflow.com\u002Fsearch?q=%28%5Btypescript%5D+or+%5Bjavascript%5D+or+%5Bnode.js%5D%29+and+%5Bmongodb%5D) |\n| Source Code              | [github.com\u002Fmongodb\u002Fnode-mongodb-native](https:\u002F\u002Fgithub.com\u002Fmongodb\u002Fnode-mongodb-native)                                              |\n| Upgrade to v7            | [etc\u002Fnotes\u002FCHANGES_7.0.0.md](https:\u002F\u002Fgithub.com\u002Fmongodb\u002Fnode-mongodb-native\u002Fblob\u002FHEAD\u002Fetc\u002Fnotes\u002FCHANGES_7.0.0.md)                     |\n| Contributing             | [CONTRIBUTING.md](https:\u002F\u002Fgithub.com\u002Fmongodb\u002Fnode-mongodb-native\u002Fblob\u002FHEAD\u002FCONTRIBUTING.md)                                           |\n| Changelog                | [HISTORY.md](https:\u002F\u002Fgithub.com\u002Fmongodb\u002Fnode-mongodb-native\u002Fblob\u002FHEAD\u002FHISTORY.md)                                                     |\n\n### Release Integrity\n\nReleases are created automatically and signed using the [Node team's GPG key](https:\u002F\u002Fpgp.mongodb.com\u002Fnode-driver.asc). This applies to the git tag as well as all release packages provided as part of a GitHub release. To verify the provided packages, download the key and import it using gpg:\n\n```shell\ngpg --import node-driver.asc\n```\n\nThe GitHub release contains a detached signature file for the NPM package (named\n`mongodb-X.Y.Z.tgz.sig`).\n\nThe following command returns the link npm package.\n\n```shell\nnpm view mongodb@vX.Y.Z dist.tarball\n```\n\nUsing the result of the above command, a `curl` command can return the official npm package for the release.\n\nTo verify the integrity of the downloaded package, run the following command:\n\n```shell\ngpg --verify mongodb-X.Y.Z.tgz.sig mongodb-X.Y.Z.tgz\n```\n\n> [!Note]\n> No verification is done when using npm to install the package. The contents of the Github tarball and npm's tarball are identical.\n\nThe MongoDB Node.js driver follows [semantic versioning](https:\u002F\u002Fsemver.org\u002F) for its releases.\n\n### Bugs \u002F Feature Requests\n\nThink you’ve found a bug? Want to see a new feature in `node-mongodb-native`? Please open a\ncase in our issue management tool, JIRA:\n\n- Create an account and login [jira.mongodb.org](https:\u002F\u002Fjira.mongodb.org).\n- Navigate to the NODE project [jira.mongodb.org\u002Fbrowse\u002FNODE](https:\u002F\u002Fjira.mongodb.org\u002Fbrowse\u002FNODE).\n- Click **Create Issue** - Please provide as much information as possible about the issue type and how to reproduce it.\n\nBug reports in JIRA for all driver projects (i.e. NODE, PYTHON, CSHARP, JAVA) and the\nCore Server (i.e. SERVER) project are **public**.\n\n### Support \u002F Feedback\n\nFor issues with, questions about, or feedback for the Node.js driver, please look into our [support channels](https:\u002F\u002Fwww.mongodb.com\u002Fdocs\u002Fmanual\u002Fsupport). Please do not email any of the driver developers directly with issues or questions - you're more likely to get an answer on the [MongoDB Community Forums](https:\u002F\u002Fcommunity.mongodb.com\u002Ftags\u002Fc\u002Fdrivers-odms-connectors\u002F7\u002Fnode-js-driver).\n\n### Change Log\n\nChange history can be found in [`HISTORY.md`](https:\u002F\u002Fgithub.com\u002Fmongodb\u002Fnode-mongodb-native\u002Fblob\u002FHEAD\u002FHISTORY.md).\n\n### Compatibility\n\nThe driver currently supports 4.2+ servers.\n\nFor exhaustive server and runtime version compatibility matrices, please refer to the following links:\n\n- [MongoDB](https:\u002F\u002Fwww.mongodb.com\u002Fdocs\u002Fdrivers\u002Fnode\u002Fcurrent\u002Fcompatibility\u002F#mongodb-compatibility)\n- [NodeJS](https:\u002F\u002Fwww.mongodb.com\u002Fdocs\u002Fdrivers\u002Fnode\u002Fcurrent\u002Fcompatibility\u002F#language-compatibility)\n\n#### Component Support Matrix\n\nThe following table describes add-on component version compatibility for the Node.js driver. Only packages with versions in these supported ranges are stable when used in combination.\n\n| Component                                                                            | `mongodb@3.x`      | `mongodb@4.x`      | `mongodb@5.x`      | `mongodb@\u003C6.12` | `mongodb@>=6.12`   | `mongodb@7.x` |\n| ------------------------------------------------------------------------------------ | ------------------ | ------------------ | ------------------ | --------------- | ------------------ | ------------- |\n| [bson](https:\u002F\u002Fwww.npmjs.com\u002Fpackage\u002Fbson)                                           | ^1.0.0             | ^4.0.0             | ^5.0.0             | ^6.0.0          | ^6.0.0             | ^7.0.0        |\n| [bson-ext](https:\u002F\u002Fwww.npmjs.com\u002Fpackage\u002Fbson-ext)                                   | ^1.0.0 \\|\\| ^2.0.0 | ^4.0.0             | N\u002FA                | N\u002FA             | N\u002FA                | N\u002FA           |\n| [kerberos](https:\u002F\u002Fwww.npmjs.com\u002Fpackage\u002Fkerberos)                                   | ^1.0.0             | ^1.0.0 \\|\\| ^2.0.0 | ^1.0.0 \\|\\| ^2.0.0 | ^2.0.1          | ^2.0.1             | ^7.0.0        |\n| [mongodb-client-encryption](https:\u002F\u002Fwww.npmjs.com\u002Fpackage\u002Fmongodb-client-encryption) | ^1.0.0             | ^1.0.0 \\|\\| ^2.0.0 | ^2.3.0             | ^6.0.0          | ^6.0.0             | ^7.0.0        |\n| [mongodb-legacy](https:\u002F\u002Fwww.npmjs.com\u002Fpackage\u002Fmongodb-legacy)                       | N\u002FA                | ^4.0.0             | ^5.0.0             | ^6.0.0          | ^6.0.0             | N\u002FA           |\n| [@mongodb-js\u002Fzstd](https:\u002F\u002Fwww.npmjs.com\u002Fpackage\u002F@mongodb-js\u002Fzstd)                   | N\u002FA                | ^1.0.0             | ^1.0.0             | ^1.1.0          | ^1.1.0 \\|\\| ^2.0.0 | ^7.0.0        |\n\n#### Typescript Version\n\nWe recommend using the latest version of typescript, however we currently ensure the driver's public types compile against `typescript@5.6.0`.\nThis is the lowest typescript version guaranteed to work with our driver: older versions may or may not work - use at your own risk.\nSince typescript [does not restrict breaking changes to major versions](https:\u002F\u002Fgithub.com\u002FMicrosoft\u002FTypeScript\u002Fwiki\u002FBreaking-Changes), we consider this support best effort.\nIf you run into any unexpected compiler failures against our supported TypeScript versions, please let us know by filing an issue on our [JIRA](https:\u002F\u002Fjira.mongodb.org\u002Fbrowse\u002FNODE).\n\nAdditionally, our Typescript types are compatible with the ECMAScript standard for our minimum supported Node version. Currently, our Typescript targets es2023.\n\n#### Running in Custom Runtimes\n\nWe are working on removing Node.js as a dependency of the driver, so that in the future it will be possible to use the driver in non-Node environments.\nThis work is currently in progress, and if you're curious, this is [our first runtime adapter commit](https:\u002F\u002Fgithub.com\u002Fmongodb\u002Fnode-mongodb-native\u002Fcommit\u002Fd2ad07f20903d86334da81222a6df9717f76faaa).\n\nSome things to keep in mind if you are using a non-Node runtime:\n\n1. Users of Webpack\u002FVite may need to prevent `crypto` polyfill injection.\n2. Auth mechanism `SCRAM-SHA-1` has a hard dependency on Node.js.\n3. Auth mechanism `SCRAM-SHA-1` is not supported in FIPS mode.\n\n## Installation\n\nThe recommended way to get started using the Node.js driver is by using the `npm` (Node Package Manager) to install the dependency in your project.\n\nAfter you've created your own project using `npm init`, you can run:\n\n```bash\nnpm install mongodb\n```\n\nThis will download the MongoDB driver and add a dependency entry in your `package.json` file.\n\nIf you are a Typescript user, you will need the Node.js type definitions to use the driver's definitions:\n\n```sh\nnpm install -D @types\u002Fnode\n```\n\n## Driver Extensions\n\nThe MongoDB driver can optionally be enhanced by the following feature packages:\n\nMaintained by MongoDB:\n\n- Zstd network compression - [@mongodb-js\u002Fzstd](https:\u002F\u002Fgithub.com\u002Fmongodb-js\u002Fzstd)\n- MongoDB field level and queryable encryption - [mongodb-client-encryption](https:\u002F\u002Fgithub.com\u002Fmongodb\u002Flibmongocrypt#readme)\n- GSSAPI \u002F SSPI \u002F Kerberos authentication - [kerberos](https:\u002F\u002Fgithub.com\u002Fmongodb-js\u002Fkerberos)\n\nSome of these packages include native C++ extensions.\nConsult the [trouble shooting guide here](https:\u002F\u002Fgithub.com\u002Fmongodb\u002Fnode-mongodb-native\u002Fblob\u002FHEAD\u002Fetc\u002Fnotes\u002Fnative-extensions.md) if you run into compilation issues.\n\nThird party:\n\n- Snappy network compression - [snappy](https:\u002F\u002Fgithub.com\u002FBrooooooklyn\u002Fsnappy)\n- AWS authentication - [@aws-sdk\u002Fcredential-providers](https:\u002F\u002Fgithub.com\u002Faws\u002Faws-sdk-js-v3\u002Ftree\u002Fmain\u002Fpackages\u002Fcredential-providers)\n\n## Quick Start\n\nThis guide will show you how to set up a simple application using Node.js and MongoDB. Its scope is only how to set up the driver and perform the simple CRUD operations. For more in-depth coverage, see the [official documentation](https:\u002F\u002Fwww.mongodb.com\u002Fdocs\u002Fdrivers\u002Fnode\u002F).\n\n### Create the `package.json` file\n\nFirst, create a directory where your application will live.\n\n```bash\nmkdir myProject\ncd myProject\n```\n\nEnter the following command and answer the questions to create the initial structure for your new project:\n\n```bash\nnpm init -y\n```\n\nNext, install the driver as a dependency.\n\n```bash\nnpm install mongodb\n```\n\n### Start a MongoDB Server\n\nFor complete MongoDB installation instructions, see [the manual](https:\u002F\u002Fwww.mongodb.com\u002Fdocs\u002Fmanual\u002Finstallation\u002F).\n\n1. Download the right MongoDB version from [MongoDB](https:\u002F\u002Fwww.mongodb.org\u002Fdownloads)\n2. Create a database directory (in this case under **\u002Fdata**).\n3. Install and start a `mongod` process.\n\n```bash\nmongod --dbpath=\u002Fdata\n```\n\nYou should see the **mongod** process start up and print some status information.\n\n### Connect to MongoDB\n\nCreate a new **app.js** file and add the following code to try out some basic CRUD\noperations using the MongoDB driver.\n\nAdd code to connect to the server and the database **myProject**:\n\n> **NOTE:** Resolving DNS Connection issues\n>\n> Node.js 18 changed the default DNS resolution ordering from always prioritizing IPv4 to the ordering\n> returned by the DNS provider. In some environments, this can result in `localhost` resolving to\n> an IPv6 address instead of IPv4 and a consequent failure to connect to the server.\n>\n> This can be resolved by:\n>\n> - specifying the IP address family using the MongoClient `family` option (`MongoClient(\u003Curi>, { family: 4 } )`)\n> - launching mongod or mongos with the ipv6 flag enabled ([--ipv6 mongod option documentation](https:\u002F\u002Fwww.mongodb.com\u002Fdocs\u002Fmanual\u002Freference\u002Fprogram\u002Fmongod\u002F#std-option-mongod.--ipv6))\n> - using a host of `127.0.0.1` in place of localhost\n> - specifying the DNS resolution ordering with the `--dns-resolution-order` Node.js command line argument (e.g. `node --dns-resolution-order=ipv4first`)\n\n```js\nconst { MongoClient } = require('mongodb');\n\u002F\u002F or as an es module:\n\u002F\u002F import { MongoClient } from 'mongodb'\n\n\u002F\u002F Connection URL\nconst url = 'mongodb:\u002F\u002Flocalhost:27017';\nconst client = new MongoClient(url);\n\n\u002F\u002F Database Name\nconst dbName = 'myProject';\n\nasync function main() {\n  \u002F\u002F Use connect method to connect to the server\n  await client.connect();\n  console.log('Connected successfully to server');\n  const db = client.db(dbName);\n  const collection = db.collection('documents');\n\n  \u002F\u002F the following code examples can be pasted here...\n\n  return 'done.';\n}\n\nmain()\n  .then(console.log)\n  .catch(console.error)\n  .finally(() => client.close());\n```\n\nRun your app from the command line with:\n\n```bash\nnode app.js\n```\n\nThe application should print **Connected successfully to server** to the console.\n\n### Insert a Document\n\nAdd to **app.js** the following function which uses the **insertMany**\nmethod to add three documents to the **documents** collection.\n\n```js\nconst insertResult = await collection.insertMany([{ a: 1 }, { a: 2 }, { a: 3 }]);\nconsole.log('Inserted documents =>', insertResult);\n```\n\nThe **insertMany** command returns an object with information about the insert operations.\n\n### Find All Documents\n\nAdd a query that returns all the documents.\n\n```js\nconst findResult = await collection.find({}).toArray();\nconsole.log('Found documents =>', findResult);\n```\n\nThis query returns all the documents in the **documents** collection.\nIf you add this below the insertMany example, you'll see the documents you've inserted.\n\n### Find Documents with a Query Filter\n\nAdd a query filter to find only documents which meet the query criteria.\n\n```js\nconst filteredDocs = await collection.find({ a: 3 }).toArray();\nconsole.log('Found documents filtered by { a: 3 } =>', filteredDocs);\n```\n\nOnly the documents which match `'a' : 3` should be returned.\n\n### Update a document\n\nThe following operation updates a document in the **documents** collection.\n\n```js\nconst updateResult = await collection.updateOne({ a: 3 }, { $set: { b: 1 } });\nconsole.log('Updated documents =>', updateResult);\n```\n\nThe method updates the first document where the field **a** is equal to **3** by adding a new field **b** to the document set to **1**. `updateResult` contains information about whether there was a matching document to update or not.\n\n### Remove a document\n\nRemove the document where the field **a** is equal to **3**.\n\n```js\nconst deleteResult = await collection.deleteMany({ a: 3 });\nconsole.log('Deleted documents =>', deleteResult);\n```\n\n### Index a Collection\n\n[Indexes](https:\u002F\u002Fwww.mongodb.com\u002Fdocs\u002Fmanual\u002Findexes\u002F) can improve your application's\nperformance. The following function creates an index on the **a** field in the\n**documents** collection.\n\n```js\nconst indexName = await collection.createIndex({ a: 1 });\nconsole.log('index name =', indexName);\n```\n\nFor more detailed information, see the [indexing strategies page](https:\u002F\u002Fwww.mongodb.com\u002Fdocs\u002Fmanual\u002Fapplications\u002Findexes\u002F).\n\n## Error Handling\n\nIf you need to filter certain errors from our driver, we have a helpful tree of errors described in [etc\u002Fnotes\u002Ferrors.md](https:\u002F\u002Fgithub.com\u002Fmongodb\u002Fnode-mongodb-native\u002Fblob\u002FHEAD\u002Fetc\u002Fnotes\u002Ferrors.md).\n\nIt is our recommendation to use `instanceof` checks on errors and to avoid relying on parsing `error.message` and `error.name` strings in your code.\nWe guarantee `instanceof` checks will pass according to semver guidelines, but errors may be sub-classed or their messages may change at any time, even patch releases, as we see fit to increase the helpfulness of the errors.\n\nAny new errors we add to the driver will directly extend an existing error class and no existing error will be moved to a different parent class outside of a major release.\nThis means `instanceof` will always be able to accurately capture the errors that our driver throws.\n\n```typescript\nconst client = new MongoClient(url);\nawait client.connect();\nconst collection = client.db().collection('collection');\n\ntry {\n  await collection.insertOne({ _id: 1 });\n  await collection.insertOne({ _id: 1 }); \u002F\u002F duplicate key error\n} catch (error) {\n  if (error instanceof MongoServerError) {\n    console.log(`Error worth logging: ${error}`); \u002F\u002F special case for some reason\n  }\n  throw error; \u002F\u002F still want to crash\n}\n```\n\n## Nightly releases\n\nIf you need to test with a change from the latest `main` branch, our `mongodb` npm package has nightly versions released under the `nightly` tag.\n\n```sh\nnpm install mongodb@nightly\n```\n\nNightly versions are published regardless of testing outcome.\nThis means there could be semantic breakages or partially implemented features.\nThe nightly build is not suitable for production use.\n\n## Next Steps\n\n- [MongoDB Documentation](https:\u002F\u002Fwww.mongodb.com\u002Fdocs\u002Fmanual\u002F)\n- [MongoDB Node Driver Documentation](https:\u002F\u002Fwww.mongodb.com\u002Fdocs\u002Fdrivers\u002Fnode\u002F)\n- [Read about Schemas](https:\u002F\u002Fwww.mongodb.com\u002Fdocs\u002Fmanual\u002Fcore\u002Fdata-modeling-introduction\u002F)\n- [Star us on GitHub](https:\u002F\u002Fgithub.com\u002Fmongodb\u002Fnode-mongodb-native)\n\n## License\n\n[Apache 2.0](LICENSE.md)\n\n© 2012-present MongoDB [Contributors](https:\u002F\u002Fgithub.com\u002Fmongodb\u002Fnode-mongodb-native\u002Fblob\u002FHEAD\u002FCONTRIBUTORS.md) \\\n© 2009-2012 Christian Amor Kvalheim\n","mongodb\u002Fnode-mongodb-native 是 MongoDB 官方提供的 Node.js 驱动程序，用于在 Node.js 应用中操作 MongoDB 数据库。该项目采用 TypeScript 编写，支持完整的 CRUD 操作以及聚合查询等高级功能，并且遵循 Apache License 2.0 开源协议。该驱动程序具有良好的性能和稳定性，能够满足从简单的数据存储需求到复杂的分布式应用开发等各种场景。对于需要使用 NoSQL 数据库来存储非结构化或半结构化数据的 Node.js 项目来说，这是一个非常理想的选择。",2,"2026-06-11 03:26:53","top_topic"]