MongoDB作为实时数据库

时间:2018-06-11 07:10:29

标签: mongodb firebase ionic3 real-time google-cloud-firestore

我有实时数据库firestore的经验。目前,我正在使用MongoDB开发Ionic 3应用程序。在该应用程序上,我们必须使用pull to refresh功能来更新最新内容。但如果我们有实时数据库,那么我们就不需要拥有这样的功能。由于上述问题,我的客户现在想要使用firestore。但我们所面临的关键问题是数据迁移。那是MongoDB到firestore。目前,这个应用程序正在生产(即应用商店),拥有超过500个用户。因为将应用程序转换为firestore将是一项非常困难的任务。所以我的问题是,我们不能在MongoDB中使用实时数据库功能吗?

注意: 我使用Nodejs/Express作为Restfull api。

1 个答案:

答案 0 :(得分:2)

你的后端是什么?如何使用socket.io

由于您已经使用过MongoDB和Express,以下是一个示例:

服务器文件:

var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);

app.get('/api/add', function(req, res){
    db.collection('quotes').save(req.body, (err, result) => {
        if (err) return console.log(err)

        // send everyone the added data
        io.emit('ADDED_DATA', req.body);
    });
});

http.listen(3000, function(){
    console.log('listening on *:3000');
});

在您的客户中:

<script src="/socket.io/socket.io.js"></script>

const socket = io('http://localhost:3030'); //ip and port of server

socket.on('ADDED_DATA', (data) => {
    // manipulate data
    // push to current list
    // or whatever you want
});
相关问题