I'm trying to CRUD operations on Firestore database from spring boot server, but I can't find anywhere how to: 1. Connect my spring boot server to Firestore 2. CRUD ops on my Firestore database
Can anyone help me out to connect my server to Firestore database?
Thanks
Firestore is a NoSQL document database built for automatic scaling, high performance, and ease of application development. While the Firestore interface has many of the same features as traditional databases, as a NoSQL database it differs from them in the way it describes relationships between data objects.
Cloud Firestore is Firebase's newest database for mobile app development. It builds on the successes of the Realtime Database with a new, more intuitive data model. Cloud Firestore also features richer, faster queries and scales further than the Realtime Database. Realtime Database is Firebase's original database.
Firestore allows you to run sophisticated ACID transactions against your document data. This gives you more flexibility in the way you structure your data. Focus on your application development using Firestore client-side development libraries for Web, iOS, Android, Flutter, C++, and Unity.
Cloud Firestore is a NoSQL, document-oriented database. Unlike a SQL database, there are no tables or rows. Instead, you store data in documents, which are organized into collections.
The simplest way is initialize firebase app:
InputStream serviceAccount = new FileInputStream(SERVICE_ACCOUNT_KEY);
GoogleCredentials credentials = GoogleCredentials.fromStream(serviceAccount);
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(credentials)
.build();
FirebaseApp.initializeApp(options);
and then you can run firestore database
Firestore db = FirestoreClient.getFirestore();
ApiFuture<QuerySnapshot> query = db.collection(YOUR_COLLECTION_NAME).get();
QuerySnapshot querySnapshot = query.get();
List<QueryDocumentSnapshot> documents = querySnapshot.getDocuments();
I think that it will be helpfull https://firebase.google.com/docs/guides
As per Spring Cloud GCP Documentation there is a starter library see Documentation
Also this is an example how to implement it sample project
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With