8

I'm starting a new web application and I'm very interested in Cloud Firestore as my primary database. But before I invest my time in Cloud Firestore, I need a backup plan.

Cloud Firestore is only available as a cloud service unlike other NoSQL databases such as Cassandra and Couchbase.

Choosing Cloud Firestore means that you are getting into the world of vendor lock-in.

Does this mean it is impossible to move the data stored in Cloud Firestore to another NoSQL Dababase?

I read here that data exported from one Cloud Firestore database can be imported into another Cloud Firestore database. But I want to have the option to move data to a different NoSQL database.

Is it possible? If so, could you explain roughly how to do that?

I am NOT asking for a detailed answer of how to migrate data step by step.

1
  • The question is pretty broad and I am not sure a specific answer can be provided but here's some info. Is it impossible to move data? It's very possible! Data can easily be read and then written out in some other format via an app you create; convert it to a tab delimited file, create rows/objects to be stored in an SQL database or store it as a .plist - that's really up to you. As you saw by the link you provided, you can also use the built in export feature to export data in a variety of ways. As you can see, the data can be exported so it seems you answered your own question.
    – Jay
    Commented May 4, 2019 at 14:05

3 Answers 3

8

Okay guys same problem. Solution for migration from Firestore to Mongodb

npm install @sgg10/firestore-backup

const firestoreBackup = require('@sgg10/firestore-backup');
const serviceAccount = require('./key');

let fsb = new firestoreBackup(serviceAccount, 'https://you data base link here');

// fsb.exportAll().then(result => fsb.saveFile(result, { name: 'All'}));

fsb.exportCustom(['users']).then(result => fsb.saveFile(result, { name: 'users'}));

Next, we have json file, so, parse this file and save to Mongodb as one docs.

npm install mongodb --save

const { MongoClient } = require('mongodb');
const jsonFile = require('./users.json');

const MONGO_USERNAME = '';
const MONGO_PASSWORD = '';
const MONGO_HOSTNAME = '';
const MONGO_PORT = '27017';
const MONGO_DB = '';
const AUTH_SOURCE = '';

const url = `mongodb://${MONGO_USERNAME}:${MONGO_PASSWORD}@${MONGO_HOSTNAME}:${MONGO_PORT}/${MONGO_DB}?authSource=${AUTH_SOURCE}`;
const client = new MongoClient(url, { useUnifiedTopology: true });

const start = async () => {
    await client.connect()
    .then(() => console.log('success'))
    .catch(() => console.log('error'))
}

const saveToDb = () => {
    const database = client.db(MONGO_DB);
    const users = database.collection("users");
    const userKeys = Object.keys(jsonFile.users);
    for (let i = 0; i < userKeys.length; i++) {
    users.insertOne({ _id: userKeys[i], ...jsonFile.users[userKeys[i]] })
    }
}
start().then(() => {
    saveToDb();
})
4

If both databases have an API, then it's possible to migrate data from one to the other. But given the difference in NoSQL database, it is extremely unlikely that there is anything automated to do this migration. And since there's no standard API for NoSQL databases, you will also need to modify your application code to work with your new database.

The "easiest" type of migration will be to another collection/document based database. In that case it's a matter of iterating over each collection in Firestore, and recreating the corresponding data structures in your new database.

0

If you want export a file and then import it in another database that seems plausible only under very restricted conditions.

  • First both databases have to be able to write and read the same dump type of file.

  • Second both databases have to have the same physical implementation or the second has to be able automatic ETL from the original dump file

So is not only a Cloud Firestore databse problem but also a destination problem.

The kind of migration you are talking about seems to be more related to SQL databases where you can open any dump file.

The conceptual problem you are facing is; using a database as a service is a SERVICE. And the advantage of it is to reduce implementation work hours. By example you can move postgres databases on Heroku, but you have to implement the server. Every service provider will be different because that is how they compete, by having different physical implementations vendors have stronger points that differentiated them from others.

Finally, you can always acces your database. This means that migrating can be done reading the original database and then posting the same content to another database. This migration process has to consider differences between services. And should be donde in a trusted enviroment, plenty of this services offers admin sdks to work with.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.