I had the same problem, the solution was to comment the line .setProjectId(projectId)
.
this example is for a native firestore instance, located in another GCP project
GoogleCredentials credentials = GoogleCredentials.fromStream(new ClassPathResource("/test-firebase.json").getInputStream());
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(credentials)
//.setProjectId(projectId)
.setDatabaseUrl("https://document-db.firebaseio.com/")
.build();
if (FirebaseApp.getApps().isEmpty()) {
FirebaseApp.initializeApp(options);
}
Firestore db = FirestoreClient.getFirestore();
DocumentReference docRef = db.collection("document-db").document("alovelace");
// Add document data with id "alovelace" using a hashmap
Map<String, Object> data = new HashMap<>();
data.put("first", "Ada");
data.put("last", "Lovelace");
data.put("born", 1815);
// asynchronously write data
ApiFuture<WriteResult> result = docRef.set(data);