Home > Backend Development > Golang > How to connect to a non-default firestore database using Go?

How to connect to a non-default firestore database using Go?

王林
Release: 2024-02-08 21:05:23
forward
1195 people have browsed it

如何使用 Go 连接到非默认 firestore 数据库?

In this article, php editor Xiaoxin will introduce to you how to use Go language to connect to a non-default Firestore database. Firestore is a flexible and scalable NoSQL document database, but by default it only connects to the default database for Google Cloud projects. However, sometimes we may need to connect to a different database, and this article will teach you how to achieve this. Whether you are a newbie or an experienced developer, this article will provide you with easy-to-follow steps and sample code to help you successfully connect to a non-default Firestore database. let's start!

Question content

I saw a post about using node to connect to a non-default Firestore database. I was wondering if anyone knows the same functionality in the firestore Go package?

I tried direct translation but no success. Maybe the package hasn't been updated with this feature yet?


Correct answer


Call NewClientWithDatabase to connect to a specific database.

ctx := context.Background()
client, err := firestore.NewClientWithDatabase(ctx, projectID, databaseID)
if err != nil {
    // TODO: Handle error.
}
defer client.Close() // Close client when done.
Copy after login

The above is the detailed content of How to connect to a non-default firestore database using Go?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template