Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firestore & Spring Boot

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

like image 796
nirh216 Avatar asked Jan 17 '18 17:01

nirh216


People also ask

What is firestore?

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.

What is difference between Firebase and firestore?

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.

What is Google firestore used for?

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.

Is firestore a SQL database?

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.


2 Answers

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

like image 77
Greg Avatar answered Oct 24 '22 17:10

Greg


As per Spring Cloud GCP Documentation there is a starter library see Documentation

Also this is an example how to implement it sample project

like image 34
Jorge L. Morla Avatar answered Oct 24 '22 18:10

Jorge L. Morla