Send feedback
Class Datastore Stay organized with collections
Save and categorize content based on your preferences.
Version 6.5.0 keyboard_arrow_down
Idiomatic class for interacting with Cloud Datastore. Uses the lower-level DatastoreClient
class under the hood.
In addition to the constructor options shown here, the Datastore
class constructor accepts the same options accepted by DatastoreClient
.
The Datastore Emulator
Make sure you have the gcloud SDK installed
, then run:
$ gcloud beta emulators datastore start --no-legacy
You will see the following printed:
\[datastore\] API endpoint: http://localhost:8005 \[datastore\] If you are using a library that supports the DATASTORE\_EMULATOR\_HOST environment variable, run: \[datastore\] \[datastore\] export DATASTORE\_EMULATOR\_HOST=localhost:8005 \[datastore\] \[datastore\] Dev App Server is now running.
Set that environment variable and your localhost Datastore will automatically be used. You can also pass this address in manually with apiEndpoint
.
Additionally, DATASTORE_PROJECT_ID
is recognized. If you have this set, you don't need to provide a projectId
.
See Cloud Datastore Concepts Overview
Inheritance
DatastoreRequest
>
Datastore
Package
@google-cloud/datastore
Constructors
(constructor)(options)
constructor
(
options
?:
DatastoreOptions
);
Constructs a new instance of the Datastore
class
Parameter
Properties
auth
Property Value
baseUrl_
Property Value
clients_
clients_
:
Map<string
,
ClientStub
> ;
Property Value
customEndpoint_
customEndpoint_
?:
boolean
;
Property Value
DatastoreRequest
DatastoreRequest
:
typeof
DatastoreRequest
;
DatastoreRequest
class.
Datastore.DatastoreRequest DatastoreRequest {constructor}
Property Value
defaultBaseUrl_
defaultBaseUrl_
:
string
;
Property Value
KEY
KEY
:
typeof
entity
.
KEY_SYMBOL
;
Property Value
KEY
static
KEY
:
typeof
entity
.
KEY_SYMBOL
;
Access the Key from an Entity object.
Datastore#KEY {symbol}
Property Value
MORE_RESULTS_AFTER_CURSOR
MORE_RESULTS_AFTER_CURSOR
:
string
;
Property Value
MORE_RESULTS_AFTER_CURSOR
static
MORE_RESULTS_AFTER_CURSOR
:
string
;
This is one of three values which may be returned from , , and as info.moreResults
.
There *may* be more results after the specified end cursor.
{string}
Property Value
MORE_RESULTS_AFTER_LIMIT
MORE_RESULTS_AFTER_LIMIT
:
string
;
Property Value
MORE_RESULTS_AFTER_LIMIT
static
MORE_RESULTS_AFTER_LIMIT
:
string
;
This is one of three values which may be returned from , , and as info.moreResults
.
There *may* be more results after the specified limit.
{string}
Property Value
namespace
Property Value
NO_MORE_RESULTS
NO_MORE_RESULTS
:
string
;
Property Value
NO_MORE_RESULTS
static
NO_MORE_RESULTS
:
string
;
This is one of three values which may be returned from , , and as info.moreResults
.
There are no more results left to query for.
{string}
Property Value
options
options
:
DatastoreOptions
;
Property Value
port_
Property Value
Query
Query
class.
Datastore.Query Query {constructor}
Property Value
Transaction
Transaction
:
typeof
Transaction
;
Transaction
class.
Datastore.Transaction Transaction {constructor}
Property Value
Methods
createQuery(kind)
createQuery
(
kind
?:
string
)
:
Query
;
Parameter
Returns
createQuery(kind)
createQuery
(
kind
?:
string
[])
:
Query
;
Parameter
Returns
createQuery(namespace, kind)
createQuery
(
namespace
:
string
,
kind
:
string
)
:
Query
;
Parameters
Returns
createQuery(namespace, kind)
createQuery
(
namespace
:
string
,
kind
:
string
[])
:
Query
;
Parameters
Returns
determineBaseUrl_(customApiEndpoint)
determineBaseUrl_
(
customApiEndpoint
?:
string
)
:
void
;
Determine the appropriate endpoint to use for API requests. If not explicitly defined, check for the "DATASTORE_EMULATOR_HOST" environment variable, used to connect to a local Datastore server.
Parameter Name
Description
customApiEndpoint
string
Custom API endpoint.
Returns
double(value)
double
(
value
:
number
)
:
entity
.
Double
;
Parameter
Returns
double(value)
static
double
(
value
:
number
)
:
entity
.
Double
;
Helper function to get a Datastore Double object.
Parameter
Returns
export(config)
export
(
config
:
ExportEntitiesConfig
)
:
Promise<LongRunningResponse>
;
Parameter
Returns
export(config, callback)
export
(
config
:
ExportEntitiesConfig
,
callback
:
LongRunningCallback
)
:
void
;
Parameters
Returns
geoPoint(coordinates)
geoPoint
(
coordinates
:
entity
.
Coordinates
)
:
entity
.
GeoPoint
;
Parameter
Returns
geoPoint(coordinates)
static
geoPoint
(
coordinates
:
entity
.
Coordinates
)
:
entity
.
GeoPoint
;
Helper function to get a Datastore Geo Point object.
Parameter Name
Description
coordinates
entity.Coordinates
Coordinate value.
Returns
getIndexes(options)
getIndexes
(
options
?:
GetIndexesOptions
)
:
Promise<GetIndexesResponse>
;
Parameter
Returns
getIndexes(options, callback)
getIndexes
(
options
:
GetIndexesOptions
,
callback
:
GetIndexesCallback
)
:
void
;
Parameters
Returns
getIndexes(callback)
getIndexes
(
callback
:
GetIndexesCallback
)
:
void
;
Parameter
Returns
getIndexesStream(options)
getIndexesStream
(
options
?:
GetIndexesOptions
)
:
NodeJS
.
ReadableStream
;
Get all of the indexes in this project as a readable object stream.
Parameter Name
Description
options
GetIndexesOptions
Configuration object. See for a complete list of options.
Returns
getProjectId()
getProjectId
()
:
Promise<string>
;
Returns
import(config)
import
(
config
:
ImportEntitiesConfig
)
:
Promise<LongRunningResponse>
;
Parameter
Returns
import(config, callback)
import
(
config
:
ImportEntitiesConfig
,
callback
:
LongRunningCallback
)
:
void
;
Parameters
Returns
index(id)
index
(
id
:
string
)
:
Index
;
Get a reference to an Index.
Parameter Name
Description
id
string
The index name or id.
Returns
insert(entities)
insert
(
entities
:
Entities
)
:
Promise<InsertResponse>
;
Parameter
Returns
insert(entities, callback)
insert
(
entities
:
Entities
,
callback
:
InsertCallback
)
:
void
;
Parameters
Returns
int(value)
int
(
value
:
number
|
string
)
:
entity
.
Int
;
Parameter Name
Description
value
number | string
Returns
int(value)
static
int
(
value
:
number
|
string
)
:
entity
.
Int
;
Helper function to get a Datastore Integer object.
This is also useful when using an ID outside the bounds of a JavaScript Number object.
Parameter Name
Description
value
number | string
The integer value.
Returns
isDouble(value)
isDouble
(
value
?:
{})
:
boolean
;
Parameter
Returns
isDouble(value)
static
isDouble
(
value
?:
{})
:
boolean
;
Helper function to check if something is a Datastore Double object.
Parameter
Returns
isGeoPoint(value)
isGeoPoint
(
value
?:
{})
:
boolean
;
Parameter
Returns
isGeoPoint(value)
static
isGeoPoint
(
value
?:
{})
:
boolean
;
Helper function to check if something is a Datastore Geo Point object.
Parameter
Returns
isInt(value)
isInt
(
value
?:
{})
:
boolean
;
Parameter
Returns
isInt(value)
static
isInt
(
value
?:
{})
:
boolean
;
Helper function to check if something is a Datastore Integer object.
Parameter
Returns
isKey(value)
isKey
(
value
?:
{})
:
boolean
;
Parameter
Returns
isKey(value)
static
isKey
(
value
?:
{})
:
boolean
;
Helper function to check if something is a Datastore Key object.
Parameter
Returns
key(options)
key
(
options
:
entity
.
KeyOptions
)
:
entity
.
Key
;
Parameter
Returns
key(path)
key
(
path
:
PathType
[])
:
entity
.
Key
;
Parameter
Returns
key(path)
key
(
path
:
string
)
:
entity
.
Key
;
Parameter
Returns
keyFromLegacyUrlsafe(key)
keyFromLegacyUrlsafe
(
key
:
string
)
:
entity
.
Key
;
Helper to convert URL safe key string to entity key object
This is intended to work with the "legacy" representation of a datastore "Key" used within Google App Engine (a so-called "Reference").
Parameter Name
Description
key
string
Entity key object.
Returns Type
Description
entity.Key
{string} Created urlsafe key.
keyToLegacyUrlSafe(key, locationPrefix)
keyToLegacyUrlSafe
(
key
:
entity
.
Key
,
locationPrefix
?:
string
)
:
Promise<string>
;
Parameters
Returns
keyToLegacyUrlSafe(key, callback)
keyToLegacyUrlSafe
(
key
:
entity
.
Key
,
callback
:
KeyToLegacyUrlSafeCallback
)
:
void
;
Parameters
Returns
keyToLegacyUrlSafe(key, locationPrefix, callback)
keyToLegacyUrlSafe
(
key
:
entity
.
Key
,
locationPrefix
:
string
,
callback
:
KeyToLegacyUrlSafeCallback
)
:
void
;
Parameters
Returns
save(entities, gaxOptions)
save
(
entities
:
Entities
,
gaxOptions
?:
CallOptions
)
:
Promise<SaveResponse>
;
Parameters
Returns
save(entities, gaxOptions, callback)
save
(
entities
:
Entities
,
gaxOptions
:
CallOptions
,
callback
:
SaveCallback
)
:
void
;
Parameters
Returns
save(entities, callback)
save
(
entities
:
Entities
,
callback
:
SaveCallback
)
:
void
;
Parameters
Returns
transaction(options)
transaction
(
options
?:
TransactionOptions
)
:
Transaction
;
Create a new Transaction object.
Parameter
Returns
update(entities)
update
(
entities
:
Entities
)
:
Promise<UpdateResponse>
;
Parameter
Returns
update(entities, callback)
update
(
entities
:
Entities
,
callback
:
UpdateCallback
)
:
void
;
Parameters
Returns
upsert(entities)
upsert
(
entities
:
Entities
)
:
Promise<UpsertResponse>
;
Parameter
Returns
upsert(entities, callback)
upsert
(
entities
:
Entities
,
callback
:
UpsertCallback
)
:
void
;
Parameters
Returns
Send feedback
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License
, and code samples are licensed under the Apache 2.0 License
. For details, see the Google Developers Site Policies
. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-09-04 UTC.
Need to tell us more?
[[["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-09-04 UTC."],[],[],null,[]]