Creates a new object for connecting to the Datastore service.
Each call creates a new connection.
For more information on connecting to Google Cloud see the
Authentication Guide.
Parameters
project_id (String) — Identifier for a Datastore project. If not
present, the default project for the credentials is used.
credentials (String, Hash, Google::Auth::Credentials) — The path to
the keyfile as a String, the contents of the keyfile as a Hash, or a
Google::Auth::Credentials object. (See Datastore::Credentials)
scope (String, Array<String>) (defaults to: nil) —
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["# Firestore in Datastore mode API - Module Google::Cloud (v2.13.0)\n\nVersion latestkeyboard_arrow_down\n\n- [2.13.0 (latest)](/ruby/docs/reference/google-cloud-datastore/latest/Google-Cloud)\n- [2.12.0](/ruby/docs/reference/google-cloud-datastore/2.12.0/Google-Cloud)\n- [2.11.0](/ruby/docs/reference/google-cloud-datastore/2.11.0/Google-Cloud)\n- [2.10.0](/ruby/docs/reference/google-cloud-datastore/2.10.0/Google-Cloud)\n- [2.9.0](/ruby/docs/reference/google-cloud-datastore/2.9.0/Google-Cloud)\n- [2.8.0](/ruby/docs/reference/google-cloud-datastore/2.8.0/Google-Cloud)\n- [2.7.1](/ruby/docs/reference/google-cloud-datastore/2.7.1/Google-Cloud)\n- [2.6.0](/ruby/docs/reference/google-cloud-datastore/2.6.0/Google-Cloud)\n- [2.5.0](/ruby/docs/reference/google-cloud-datastore/2.5.0/Google-Cloud)\n- [2.4.0](/ruby/docs/reference/google-cloud-datastore/2.4.0/Google-Cloud)\n- [2.3.1](/ruby/docs/reference/google-cloud-datastore/2.3.1/Google-Cloud)\n- [2.2.4](/ruby/docs/reference/google-cloud-datastore/2.2.4/Google-Cloud) \nReference documentation and code samples for the Firestore in Datastore mode API module Google::Cloud.\n\nMethods\n-------\n\n### .datastore\n\n def self.datastore(project_id = nil, credentials = nil, scope: nil, timeout: nil, database_id: nil) -\u003e Google::Cloud::Datastore::Dataset\n\nCreates a new object for connecting to the Datastore service.\nEach call creates a new connection.\n\n\n\u003cbr /\u003e\n\nFor more information on connecting to Google Cloud see the\n[Authentication Guide](./AUTHENTICATION \"Authentication Guide\"). \n**Parameters**\n\n- **project_id** (String) --- Identifier for a Datastore project. If not present, the default project for the credentials is used.\n- **credentials** (String, Hash, Google::Auth::Credentials) --- The path to the keyfile as a String, the contents of the keyfile as a Hash, or a Google::Auth::Credentials object. (See [Datastore::Credentials](/ruby/docs/reference/google-cloud-datastore/latest/Google-Cloud-Datastore-Credentials \"Google::Cloud::Datastore::Credentials (class)\"))\n- **scope** (String, Array\\\u003cString\\\u003e) *(defaults to: nil)* ---\n\n The OAuth 2.0 scopes controlling the\n set of resources and operations that the connection can access. See\n [Using OAuth 2.0 to Access Google\n APIs](https://developers.google.com/identity/protocols/OAuth2).\n\n The default scope is:\n - `https://www.googleapis.com/auth/datastore`\n- **timeout** (Integer) *(defaults to: nil)* --- Default timeout to use in requests. Optional. \n**Returns**\n\n- ([Google::Cloud::Datastore::Dataset](./Google-Cloud-Datastore-Dataset))\n**Example** \n\n```ruby\nrequire \"google/cloud\"\n\ndatastore = Google::Cloud.datastore \"my-todo-project\",\n \"/path/to/keyfile.json\"\n\ntask = datastore.entity \"Task\", \"sampleTask\" do |t|\n t[\"type\"] = \"Personal\"\n t[\"done\"] = false\n t[\"priority\"] = 4\n t[\"description\"] = \"Learn Cloud Datastore\"\nend\n\ndatastore.save task\n```\n\n### #datastore\n\n def datastore(scope: nil, timeout: nil, database_id: nil) -\u003e Google::Cloud::Datastore::Dataset\n\nCreates a new object for connecting to the Datastore service.\nEach call creates a new connection.\n\n\n\u003cbr /\u003e\n\nFor more information on connecting to Google Cloud see the\n[Authentication Guide](./AUTHENTICATION \"Authentication Guide\"). \n**Parameters**\n\n- **scope** (String, Array\\\u003cString\\\u003e) *(defaults to: nil)* ---\n\n The OAuth 2.0 scopes controlling the\n set of resources and operations that the connection can access. See\n [Using OAuth 2.0 to Access Google\n APIs](https://developers.google.com/identity/protocols/OAuth2).\n\n The default scope is:\n - `https://www.googleapis.com/auth/datastore`\n- **timeout** (Integer) *(defaults to: nil)* --- Default timeout to use in requests. Optional. \n**Returns**\n\n- ([Google::Cloud::Datastore::Dataset](./Google-Cloud-Datastore-Dataset))\n**Examples** \n\n```ruby\nrequire \"google/cloud\"\n\ngcloud = Google::Cloud.new\ndatastore = gcloud.datastore\n\ntask = datastore.entity \"Task\" do |t|\n t[\"type\"] = \"Personal\"\n t[\"done\"] = false\n t[\"priority\"] = 4\n t[\"description\"] = \"Learn Cloud Datastore\"\nend\n\ndatastore.save task\n```\n\nYou shouldn't need to override the default scope, but you can: \n\n```ruby\nrequire \"google/cloud\"\n\ngcloud = Google::Cloud.new\nplatform_scope = \"https://www.googleapis.com/auth/cloud-platform\"\ndatastore = gcloud.datastore scope: platform_scope\n```"]]