我正在寻找将正在使用Firebase实时数据库的应用程序数据库迁移到新的Cloud Firestore数据库的最佳方法。我对我正在研究的项目非常有信心,我不需要对数据模式进行任何更改,所以我几乎只是试图对它进行映射。 Firebase在他们的网站上建议只写一个脚本来做到这一点,但我不确定最好的解决方法。有没有人已经完成了这个脚本?将Firebase实时数据库迁移到Firestore
回答
我写了一个小节点脚本,它以快速和肮脏的方式迁移事物,并且工作得非常好。
如果其他人感兴趣,则在下面。
注:这应该只有在实时数据库中的数据模型是完全平坦的,并没有太多的嵌套的数据,你打算使用,并保持你的数据持平,以及在公司的FireStore
运行此脚本只需创建一个名为index.js的节点文件,并将其与实时数据库导出中的服务帐户文件和原始json文件一起放入目录中,然后从命令行运行以下命令。
$ node index.js
下面的脚本实现。
const admin = require('firebase-admin');
var serviceAccount = require("./config.json");
var database = require("./database.json");
var async = require ('async');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
});
var db = admin.firestore();
var allEntityNames = Object.keys(database);
var asyncTasks = [];
for (var i in allEntityNames) {
var entityName = allEntityNames[i];
var entity = database[entityName];
var entityKeys = Object.keys(entity);
console.log("began migrating "+ entityName);
for (var j in entityKeys) {
var entityKey = entityKeys[j];
var dict = entity[entityKey];
asyncTasks.push(function(callback){
db.collection(entityName).doc(entityKey).set(dict)
.then(function() {
callback();
})
.catch(function(error) {
console.log(error);
callback();
});
});
}
async.parallel(asyncTasks, function(){
console.log("Finished migrating "+ entityName);
});
}
嗨,我已经创建了一个脚本为同
import { AngularFirestore, AngularFirestoreCollection } from 'angularfire2/firestore';
import { AngularFireDatabase } from 'angularfire2/database';
constructor(private afs: AngularFirestore, private angularfire: AngularFireDatabase) {}
convert() {
this.itemsCollection = this.afs.collection('requests');//ref()
this.angularfire.list('/requests/').auditTrail().subscribe((data: any) => {
_.each(data, element =>{
this.itemsCollection.doc(element.key).set(element.payload.val()) .then((result) => { }); }); });}
你可以添加步骤来运行这个? – Luke
是 1)配置您的Firebase项目,然后 2)添加到TS文件 从'angularfire2/firestore'导入{AngularFirestore,AngularFirestoreCollection}; 从'angularfire2/database'导入{AngularFireDatabase}; convert(){this.itemsCollection = this.afs.collection('requests'); // ref() this.angularfire.list('/请求/')。auditTrail()。subscribe((data:any)=> {ee(data,element => {this.itemsCollection.doc(element.key).set(element.payload.val )).then((result)=> {});});});} –
- 1. 将现有的实时Firebase数据库升级到Cloud Firestore
- 2. 同时使用Firebase数据库和Firestore
- 3. Mysql实时数据库迁移
- 4. 使用firebase-admin移除Firebase实时数据库上的数据
- 5. 将Mysql数据库迁移到Mssql
- 6. 将XAMPP数据库迁移到LAMP
- 7. 将数据库从Postgres迁移到MySQL
- 8. 将更改迁移到数据库
- 9. 将Wordpress(MySQL)数据库迁移到BigQuery
- 10. 将PostgreSQL数据库迁移到MySQL
- 11. 将Activerecord数据库迁移到Mongoid
- 12. 将数据库从Sybase迁移到MySQL
- 13. 将数据库SQL Server迁移到Sybase
- 14. 将Access数据库迁移到SharePoint 2007
- 15. 将Codeigniter数据库迁移到Wordpress
- 16. 将MySQL数据库迁移到Sql Server
- 17. 使用EnterpriseDB迁移工具将MySQL数据库迁移到PostgreSQL
- 18. android firebase将数据保存到实时数据库
- 19. Firebase实时数据库
- 20. Firebase实时数据库addValueEventListener
- 21. Firebase Assistant:实时数据库
- 22. 将SQL Server数据库迁移到SQL Compact数据库
- 23. 数据迁移到SQLSERVER数据库
- 24. 数据库迁移
- 25. 数据库迁移
- 26. 数据库迁移
- 27. 数据库迁移
- 28. 在实时数据库中迁移数据的查询?
- 29. Firebase实时数据库 - 检索数据
- 30. 当应用程序迁移到firebase时数据未加载
https://firebase.google.com/docs/firestore/firestore-for-rtdb –
是的,知道链接的,但他们基本上只是建议写一个脚本,但这不是这个问题所要求的。 – Luke
不太可能任何人都会为此使用通用脚本,因为它可能会根据每个人的特定用例和要求定制。 –