[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-09-04 UTC。"],[],[],null,["# Configure a MongoDB database\n\n| **Preview**\n|\n|\n| This feature is subject to the \"Pre-GA Offerings Terms\" in the General Service Terms section\n| of the [Service Specific Terms](/terms/service-terms#1).\n|\n| Pre-GA features are available \"as is\" and might have limited support.\n|\n| For more information, see the\n| [launch stage descriptions](/products#product-launch-stages).\n\n\u003cbr /\u003e\n\nThis page describes how to configure a MongoDB database for use with\nDatastream. You can configure Datastream to replicate\ndata from a fully managed cloud database service called Atlas, or, if you're\nreplicating from a self-managed MongoDB instance, using the MongoDB Shell.\n\nConfigure a MongoDB Atlas instance\n----------------------------------\n\n| **Note:** The steps that follow apply to both replica set and sharded clusters.\n\nTo use Datastream with a MongoDB Atlas instance, you first need\nto create a Datastream user and grant them database access:\n\n1. In the [MongoDB Atlas dashboard](https://www.mongodb.com/products/platform/cloud), under **Security** , click **Database access**.\n2. Click **New database user** and select the password authentication method for your user.\n3. Enter the username and password for your Datastream user.\n4. Select **Grant specific user privileges** under **Database user\n privileges**.\n5. Add these roles/privileges under **Specific privileges** :\n - `readAnyDatabase`\n6. Click **Add user**.\n\nConfigure a MongoDB self-hosted instance\n----------------------------------------\n\nThis page describes how to configure a MongoDB self-hosted database for use with\nDatastream for both replica set and sharded cluster.\n\n### Replica set\n\nFor information about deploying a MongoDB replica set, see\n[Deploy a self-managed replica set](https://www.mongodb.com/docs/manual/tutorial/deploy-replica-set/)\nin MongoDB documentation.\n\nTo configure Datastream for use with a self-managed MongoDB\nreplica set, follow these steps:\n\n1. Install the MongoDB Shell. For information about installing the MongoDB Shell, see the [MongoDB documentation](https://www.mongodb.com/docs/mongodb-shell/install/).\n2. Open the terminal and run the `mongosh` command to connect to your replica set or primary node.\n3. Create a user for Datastream in the `admin` database:\n\n use admin\n db.createUser({\n user: \"\u003cvar translate=\"no\"\u003eUSERNAME\u003c/var\u003e\",\n pwd: \"\u003cvar translate=\"no\"\u003ePASSWORD\u003c/var\u003e\",\n roles: [ \"readAnyDatabase\", {role: \"read\", db: \"admin\"} ]\n })\n\nReplace \u003cvar translate=\"no\"\u003eUSERNAME\u003c/var\u003e and \u003cvar translate=\"no\"\u003ePASSWORD\u003c/var\u003e with your username and password.\n\n### Sharded cluster\n\nFor information about deploying a sharded cluster, see\n[Deploy a sharded cluster](https://www.mongodb.com/docs/kubernetes-operator/current/tutorial/deploy-sharded-cluster/)\nin MongoDB documentation.\n\nTo configure Datastream for use with a self-managed MongoDB\nsharded cluster, follow these steps:\n\n1. Install the MongoDB Shell. For information about installing the MongoDB Shell, see the [MongoDB documentation](https://www.mongodb.com/docs/mongodb-shell/install/).\n2. Open the terminal and run the `mongosh` command to connect to your MongoDB sharded cluster.\n3. Create an identical Datastream user in every primary shard node and the `mongos` query router:\n\n use admin\n db.createUser({\n user: \"\u003cvar translate=\"no\"\u003eUSERNAME\u003c/var\u003e\",\n pwd: \"\u003cvar translate=\"no\"\u003ePASSWORD\u003c/var\u003e\",\n roles: [ \"readAnyDatabase\" ]\n })\n\nReplace \u003cvar translate=\"no\"\u003eUSERNAME\u003c/var\u003e and \u003cvar translate=\"no\"\u003ePASSWORD\u003c/var\u003e with your username and\npassword. You can pick any username and password, but it must be consistent\nacross all primary shard nodes and the mongos query router.\n\nTo find out which shards are connected to the mongos query router, run the\nfollowing command:\n\n`db.adminCommand({ listShards: 1 })`"]]