Constructor
new FirestoreClient(optionsopt)
Construct an instance of FirestoreClient.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
<optional> |
The configuration object. See the subsequent parameters for more details. Properties
|
- Source:
Members
(static) apiEndpoint
The DNS address for this API service - same as servicePath(), exists for compatibility reasons.
- Source:
(static) port
The port for this API service.
- Source:
(static) scopes
The scopes needed to make gRPC calls for every method defined in this service.
- Source:
(static) servicePath
The DNS address for this API service.
- Source:
Methods
anyPathPath(project, database, document, anyPath) → {String}
Return a fully-qualified any_path resource name string.
Parameters:
Name | Type | Description |
---|---|---|
project |
String | |
database |
String | |
document |
String | |
anyPath |
String |
- Source:
batchGetDocuments(request, optionsopt) → {Stream}
Gets multiple documents.
Documents returned by this method are not guaranteed to be returned in the same order that they were requested.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
request |
Object |
The request object that will be sent. Properties
|
|||||||||||||||||||||||||||||
options |
Object |
<optional> |
Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details. |
- Source:
Example
const firestore = require('@google-cloud/firestore');
const client = new firestore.v1beta1.FirestoreClient({
// optional auth parameters.
});
const formattedDatabase = client.databaseRootPath('[PROJECT]', '[DATABASE]');
const documents = [];
const request = {
database: formattedDatabase,
documents: documents,
};
client.batchGetDocuments(request).on('data', response => {
// doThingsWith(response)
});
beginTransaction(request, optionsopt, callbackopt) → {Promise}
Starts a new transaction.
Parameters:
Name | Type | Attributes | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
request |
Object |
The request object that will be sent. Properties
|
|||||||||||||
options |
Object |
<optional> |
Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details. |
||||||||||||
callback |
function |
<optional> |
The function which will be called with the result of the API call. The second parameter to the callback is an object representing BeginTransactionResponse. |
- Source:
Example
const firestore = require('@google-cloud/firestore');
const client = new firestore.v1beta1.FirestoreClient({
// optional auth parameters.
});
const formattedDatabase = client.databaseRootPath('[PROJECT]', '[DATABASE]');
client.beginTransaction({database: formattedDatabase})
.then(responses => {
const response = responses[0];
// doThingsWith(response)
})
.catch(err => {
console.error(err);
});
commit(request, optionsopt, callbackopt) → {Promise}
Commits a transaction, while optionally updating documents.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
request |
Object |
The request object that will be sent. Properties
|
|||||||||||||||||
options |
Object |
<optional> |
Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details. |
||||||||||||||||
callback |
function |
<optional> |
The function which will be called with the result of the API call. The second parameter to the callback is an object representing CommitResponse. |
- Source:
Example
const firestore = require('@google-cloud/firestore');
const client = new firestore.v1beta1.FirestoreClient({
// optional auth parameters.
});
const formattedDatabase = client.databaseRootPath('[PROJECT]', '[DATABASE]');
const writes = [];
const request = {
database: formattedDatabase,
writes: writes,
};
client.commit(request)
.then(responses => {
const response = responses[0];
// doThingsWith(response)
})
.catch(err => {
console.error(err);
});
createDocument(request, optionsopt, callbackopt) → {Promise}
Creates a new document.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
request |
Object |
The request object that will be sent. Properties
|
|||||||||||||||||||||||||
options |
Object |
<optional> |
Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details. |
||||||||||||||||||||||||
callback |
function |
<optional> |
The function which will be called with the result of the API call. The second parameter to the callback is an object representing Document. |
- Source:
Example
const firestore = require('@google-cloud/firestore');
const client = new firestore.v1beta1.FirestoreClient({
// optional auth parameters.
});
const formattedParent = client.anyPathPath('[PROJECT]', '[DATABASE]', '[DOCUMENT]', '[ANY_PATH]');
const collectionId = '';
const documentId = '';
const document = {};
const request = {
parent: formattedParent,
collectionId: collectionId,
documentId: documentId,
document: document,
};
client.createDocument(request)
.then(responses => {
const response = responses[0];
// doThingsWith(response)
})
.catch(err => {
console.error(err);
});
databaseRootPath(project, database) → {String}
Return a fully-qualified database_root resource name string.
Parameters:
Name | Type | Description |
---|---|---|
project |
String | |
database |
String |
- Source:
deleteDocument(request, optionsopt, callbackopt) → {Promise}
Deletes a document.
Parameters:
Name | Type | Attributes | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
request |
Object |
The request object that will be sent. Properties
|
|||||||||||||
options |
Object |
<optional> |
Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details. |
||||||||||||
callback |
function |
<optional> |
The function which will be called with the result of the API call. |
- Source:
Example
const firestore = require('@google-cloud/firestore');
const client = new firestore.v1beta1.FirestoreClient({
// optional auth parameters.
});
const formattedName = client.anyPathPath('[PROJECT]', '[DATABASE]', '[DOCUMENT]', '[ANY_PATH]');
client.deleteDocument({name: formattedName}).catch(err => {
console.error(err);
});
documentPathPath(project, database, documentPath) → {String}
Return a fully-qualified document_path resource name string.
Parameters:
Name | Type | Description |
---|---|---|
project |
String | |
database |
String | |
documentPath |
String |
- Source:
documentRootPath(project, database) → {String}
Return a fully-qualified document_root resource name string.
Parameters:
Name | Type | Description |
---|---|---|
project |
String | |
database |
String |
- Source:
getDocument(request, optionsopt, callbackopt) → {Promise}
Gets a single document.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
request |
Object |
The request object that will be sent. Properties
|
|||||||||||||||||||||
options |
Object |
<optional> |
Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details. |
||||||||||||||||||||
callback |
function |
<optional> |
The function which will be called with the result of the API call. The second parameter to the callback is an object representing Document. |
- Source:
Example
const firestore = require('@google-cloud/firestore');
const client = new firestore.v1beta1.FirestoreClient({
// optional auth parameters.
});
const formattedName = client.anyPathPath('[PROJECT]', '[DATABASE]', '[DOCUMENT]', '[ANY_PATH]');
client.getDocument({name: formattedName})
.then(responses => {
const response = responses[0];
// doThingsWith(response)
})
.catch(err => {
console.error(err);
});
getProjectId(callback)
Return the project ID used by this class.
Parameters:
Name | Type | Description |
---|---|---|
callback |
function |
the callback to be called with the current project Id. |
- Source:
listCollectionIds(request, optionsopt, callbackopt) → {Promise}
Lists all the collection IDs underneath a document.
Parameters:
Name | Type | Attributes | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
request |
Object |
The request object that will be sent. Properties
|
|||||||||||||
options |
Object |
<optional> |
Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details. |
||||||||||||
callback |
function |
<optional> |
The function which will be called with the result of the API call. The second parameter to the callback is Array of string. When autoPaginate: false is specified through options, it contains the result in a single response. If the response indicates the next page exists, the third parameter is set to be used for the next request object. The fourth parameter keeps the raw response object of an object representing ListCollectionIdsResponse. |
- Source:
Example
const firestore = require('@google-cloud/firestore');
const client = new firestore.v1beta1.FirestoreClient({
// optional auth parameters.
});
// Iterate over all elements.
const formattedParent = client.anyPathPath('[PROJECT]', '[DATABASE]', '[DOCUMENT]', '[ANY_PATH]');
client.listCollectionIds({parent: formattedParent})
.then(responses => {
const resources = responses[0];
for (const resource of resources) {
// doThingsWith(resource)
}
})
.catch(err => {
console.error(err);
});
// Or obtain the paged response.
const formattedParent = client.anyPathPath('[PROJECT]', '[DATABASE]', '[DOCUMENT]', '[ANY_PATH]');
const options = {autoPaginate: false};
const callback = responses => {
// The actual resources in a response.
const resources = responses[0];
// The next request if the response shows that there are more responses.
const nextRequest = responses[1];
// The actual response object, if necessary.
// const rawResponse = responses[2];
for (const resource of resources) {
// doThingsWith(resource);
}
if (nextRequest) {
// Fetch the next page.
return client.listCollectionIds(nextRequest, options).then(callback);
}
}
client.listCollectionIds({parent: formattedParent}, options)
.then(callback)
.catch(err => {
console.error(err);
});
listCollectionIdsStream(request, optionsopt) → {Stream}
Equivalent to listCollectionIds, but returns a NodeJS Stream object.
This fetches the paged responses for listCollectionIds continuously and invokes the callback registered for 'data' event for each element in the responses.
The returned object has 'end' method when no more elements are required.
autoPaginate option will be ignored.
Parameters:
Name | Type | Attributes | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
request |
Object |
The request object that will be sent. Properties
|
|||||||||||||
options |
Object |
<optional> |
Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details. |
Example
const firestore = require('@google-cloud/firestore');
const client = new firestore.v1beta1.FirestoreClient({
// optional auth parameters.
});
const formattedParent = client.anyPathPath('[PROJECT]', '[DATABASE]', '[DOCUMENT]', '[ANY_PATH]');
client.listCollectionIdsStream({parent: formattedParent})
.on('data', element => {
// doThingsWith(element)
}).on('error', err => {
console.log(err);
});
listDocuments(request, optionsopt, callbackopt) → {Promise}
Lists documents.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
request |
Object |
The request object that will be sent. Properties
|
|||||||||||||||||||||||||||||||||||||
options |
Object |
<optional> |
Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details. |
||||||||||||||||||||||||||||||||||||
callback |
function |
<optional> |
The function which will be called with the result of the API call. The second parameter to the callback is Array of Document. When autoPaginate: false is specified through options, it contains the result in a single response. If the response indicates the next page exists, the third parameter is set to be used for the next request object. The fourth parameter keeps the raw response object of an object representing ListDocumentsResponse. |
- Source:
Example
const firestore = require('@google-cloud/firestore');
const client = new firestore.v1beta1.FirestoreClient({
// optional auth parameters.
});
// Iterate over all elements.
const formattedParent = client.anyPathPath('[PROJECT]', '[DATABASE]', '[DOCUMENT]', '[ANY_PATH]');
const collectionId = '';
const request = {
parent: formattedParent,
collectionId: collectionId,
};
client.listDocuments(request)
.then(responses => {
const resources = responses[0];
for (const resource of resources) {
// doThingsWith(resource)
}
})
.catch(err => {
console.error(err);
});
// Or obtain the paged response.
const formattedParent = client.anyPathPath('[PROJECT]', '[DATABASE]', '[DOCUMENT]', '[ANY_PATH]');
const collectionId = '';
const request = {
parent: formattedParent,
collectionId: collectionId,
};
const options = {autoPaginate: false};
const callback = responses => {
// The actual resources in a response.
const resources = responses[0];
// The next request if the response shows that there are more responses.
const nextRequest = responses[1];
// The actual response object, if necessary.
// const rawResponse = responses[2];
for (const resource of resources) {
// doThingsWith(resource);
}
if (nextRequest) {
// Fetch the next page.
return client.listDocuments(nextRequest, options).then(callback);
}
}
client.listDocuments(request, options)
.then(callback)
.catch(err => {
console.error(err);
});
listDocumentsStream(request, optionsopt) → {Stream}
Equivalent to listDocuments, but returns a NodeJS Stream object.
This fetches the paged responses for listDocuments continuously and invokes the callback registered for 'data' event for each element in the responses.
The returned object has 'end' method when no more elements are required.
autoPaginate option will be ignored.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
request |
Object |
The request object that will be sent. Properties
|
|||||||||||||||||||||||||||||||||||||
options |
Object |
<optional> |
Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details. |
Example
const firestore = require('@google-cloud/firestore');
const client = new firestore.v1beta1.FirestoreClient({
// optional auth parameters.
});
const formattedParent = client.anyPathPath('[PROJECT]', '[DATABASE]', '[DOCUMENT]', '[ANY_PATH]');
const collectionId = '';
const request = {
parent: formattedParent,
collectionId: collectionId,
};
client.listDocumentsStream(request)
.on('data', element => {
// doThingsWith(element)
}).on('error', err => {
console.log(err);
});
listen(optionsopt) → {Stream}
Listens to changes.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
Object |
<optional> |
Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details. |
- Source:
Example
const firestore = require('@google-cloud/firestore');
const client = new firestore.v1beta1.FirestoreClient({
// optional auth parameters.
});
const stream = client.listen().on('data', response => {
// doThingsWith(response)
});
const formattedDatabase = client.databaseRootPath('[PROJECT]', '[DATABASE]');
const request = {
database: formattedDatabase,
};
// Write request objects.
stream.write(request);
matchAnyPathFromAnyPathName(anyPathName) → {String}
Parse the anyPathName from a any_path resource.
Parameters:
Name | Type | Description |
---|---|---|
anyPathName |
String |
A fully-qualified path representing a any_path resources. |
- Source:
matchDatabaseFromAnyPathName(anyPathName) → {String}
Parse the anyPathName from a any_path resource.
Parameters:
Name | Type | Description |
---|---|---|
anyPathName |
String |
A fully-qualified path representing a any_path resources. |
- Source:
matchDatabaseFromDatabaseRootName(databaseRootName) → {String}
Parse the databaseRootName from a database_root resource.
Parameters:
Name | Type | Description |
---|---|---|
databaseRootName |
String |
A fully-qualified path representing a database_root resources. |
- Source:
matchDatabaseFromDocumentPathName(documentPathName) → {String}
Parse the documentPathName from a document_path resource.
Parameters:
Name | Type | Description |
---|---|---|
documentPathName |
String |
A fully-qualified path representing a document_path resources. |
- Source:
matchDatabaseFromDocumentRootName(documentRootName) → {String}
Parse the documentRootName from a document_root resource.
Parameters:
Name | Type | Description |
---|---|---|
documentRootName |
String |
A fully-qualified path representing a document_root resources. |
- Source:
matchDocumentFromAnyPathName(anyPathName) → {String}
Parse the anyPathName from a any_path resource.
Parameters:
Name | Type | Description |
---|---|---|
anyPathName |
String |
A fully-qualified path representing a any_path resources. |
- Source:
matchDocumentPathFromDocumentPathName(documentPathName) → {String}
Parse the documentPathName from a document_path resource.
Parameters:
Name | Type | Description |
---|---|---|
documentPathName |
String |
A fully-qualified path representing a document_path resources. |
- Source:
matchProjectFromAnyPathName(anyPathName) → {String}
Parse the anyPathName from a any_path resource.
Parameters:
Name | Type | Description |
---|---|---|
anyPathName |
String |
A fully-qualified path representing a any_path resources. |
- Source:
matchProjectFromDatabaseRootName(databaseRootName) → {String}
Parse the databaseRootName from a database_root resource.
Parameters:
Name | Type | Description |
---|---|---|
databaseRootName |
String |
A fully-qualified path representing a database_root resources. |
- Source:
matchProjectFromDocumentPathName(documentPathName) → {String}
Parse the documentPathName from a document_path resource.
Parameters:
Name | Type | Description |
---|---|---|
documentPathName |
String |
A fully-qualified path representing a document_path resources. |
- Source:
matchProjectFromDocumentRootName(documentRootName) → {String}
Parse the documentRootName from a document_root resource.
Parameters:
Name | Type | Description |
---|---|---|
documentRootName |
String |
A fully-qualified path representing a document_root resources. |
- Source:
rollback(request, optionsopt, callbackopt) → {Promise}
Rolls back a transaction.
Parameters:
Name | Type | Attributes | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
request |
Object |
The request object that will be sent. Properties
|
||||||||||
options |
Object |
<optional> |
Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details. |
|||||||||
callback |
function |
<optional> |
The function which will be called with the result of the API call. |
- Source:
Example
const firestore = require('@google-cloud/firestore');
const client = new firestore.v1beta1.FirestoreClient({
// optional auth parameters.
});
const formattedDatabase = client.databaseRootPath('[PROJECT]', '[DATABASE]');
const transaction = Buffer.from('');
const request = {
database: formattedDatabase,
transaction: transaction,
};
client.rollback(request).catch(err => {
console.error(err);
});
runQuery(request, optionsopt) → {Stream}
Runs a query.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
request |
Object |
The request object that will be sent. Properties
|
|||||||||||||||||||||||||
options |
Object |
<optional> |
Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details. |
- Source:
Example
const firestore = require('@google-cloud/firestore');
const client = new firestore.v1beta1.FirestoreClient({
// optional auth parameters.
});
const formattedParent = client.anyPathPath('[PROJECT]', '[DATABASE]', '[DOCUMENT]', '[ANY_PATH]');
client.runQuery({parent: formattedParent}).on('data', response => {
// doThingsWith(response)
});
updateDocument(request, optionsopt, callbackopt) → {Promise}
Updates or inserts a document.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
request |
Object |
The request object that will be sent. Properties
|
|||||||||||||||||||||
options |
Object |
<optional> |
Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details. |
||||||||||||||||||||
callback |
function |
<optional> |
The function which will be called with the result of the API call. The second parameter to the callback is an object representing Document. |
- Source:
Example
const firestore = require('@google-cloud/firestore');
const client = new firestore.v1beta1.FirestoreClient({
// optional auth parameters.
});
const document = {};
const updateMask = {};
const request = {
document: document,
updateMask: updateMask,
};
client.updateDocument(request)
.then(responses => {
const response = responses[0];
// doThingsWith(response)
})
.catch(err => {
console.error(err);
});
write(optionsopt) → {Stream}
Streams batches of document updates and deletes, in order.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
Object |
<optional> |
Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details. |
- Source:
Example
const firestore = require('@google-cloud/firestore');
const client = new firestore.v1beta1.FirestoreClient({
// optional auth parameters.
});
const stream = client.write().on('data', response => {
// doThingsWith(response)
});
const formattedDatabase = client.databaseRootPath('[PROJECT]', '[DATABASE]');
const request = {
database: formattedDatabase,
};
// Write request objects.
stream.write(request);