I have an experience with real-time database firestore. Currently, I'm working on Ionic 3 app with MongoDB. On that app, we have to use pull to refresh feature to update the latest content. But if we have real-time DB then we don't need to have such feature. Due to above issue, my client now wants to use firestore. But the key problem where we have is data migration. That is MongoDB to firestore. Currently, this app is in production (i.e. app stores) and having over 500+ users. Because of that converting app to firestore will be a very difficult task. So my question here is, Can't we use real-time DB features with MongoDB?
Note: I use Nodejs/Express
as Restfull api.
What's your backend? How about using socket.io?
Since you're using MongoDB and Express already, here's a sample:
Server file:
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');
});
in your client:
<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
});