Local MongoDB implementation for Electron App - javascript

Im currently building a web app heavily based on MongoDB and Mongoose for the web app backend. The app will also have a desktop version based on electron. However as far as I’ve researched, including stackoverflow, you can’t package MongoDB with an electron app. The app might not be connected to the internet all the time. And hence I need a local store for it as well. This is where I want to use something like CouchDB or PouchDB.
The implementation I have come up with is this:
Store the data in a CouchDB/PouchDB
Check if there’s an Internet connection
If a connection can be established match the online MongoDB with the local CouchDB/PouchDB and add any entries not present in the database to MongoDB.
What I’d like to ask is if there’s a betterway to go about this?

Related

How to list peers to be connected to video chat on PEERJS and Angular 4?

I've followed the tutorial over building video chat with usage of PeerJs and Angular 4 (http://tphangout.com/angular-2-videochat-using-peerjs/)
Tutorial descibes it for ANg2 , but i was able to launch it with Ang 4
I plan to have a user, which sees the list of other others and can connect to any of them.
Decided to check if someone done this and might advise on following:
1) What is the best way to list users connected to Peer Server? Can this be done with some query ?
2) How to refresh the list if other users are available or disconnected?
So far, easiest way for me would be to store id of connected users in DB and query upon user visiting specific route.
ANy suggestions?
PeerJS is quite outdated, lib wasnt renewed for quite long. Ive researched and there are other options like simplewebrtc (works in chrome, ios etc) , easyrtc and others. The problem is that for those libraries there are no demo projects with Angular 2/4.
Thanks and Regards
You should save the peerjs id's to a database table, and then each client can show a list of them.
Have a look at https://github.com/mikkelking/meteor-video-call
Which is written in Meteor and Angular1.5 - it's really easy to run up, just follow the instructions (install Meteor first). It uses Meteor's reactive database to do live updates of the web pages. It uses the public peerjs server, and will only work on localhost - use Firefox for one end and Chrome for the other end of the video call.
You can ask more me questions if you want.

Using MongoDB locally (electron)?

I need to store some data as part of my electron application. I know how to set up a REST API, and serve my application like so. However, is it also possible to use (e.g.) MongoDB locally, and implement something similar to a REST API locally? I would like to not assume an internet connection for this project.
If you need to implement a mongoDB like database locally for the application without internet, you can use lowdb
Yes it is possible, you have nodejs in electron so you can use mongoose:
https://github.com/Automattic/mongoose
But in this case every person who use your application have to install mongodb in his machine.

Receive PubNub subscribe message and insert MongoDB database

I'm trying to develop a small system with a easy architecture. In this case I have one simulator that generate random data and publish this data on PubNub. Otherwise, i have too two subscribers: one web based dashboard and MongoDB database.
At this moment, I developed the simulator and the dashboard. The next stage is receive the PubNub subscribe data and insert into MongoDB.
My issue is how I can do this remotely? What is the framework that I should use? I saw many tutorials that start MongoDB DB by terminal on local machine, remotely how this works?
Someone can give me a full explication?
Regards,
Note: I use PubNub JS SDK, my dashboard was developed in HTML, CSS and JS

Synchronization between mysql and IndexedDB

I like to develop an Desktop App using nw.js (node-webkit) or Electron.
I am looking for a solution to sync between IndexedDB and MySQL Server + PHP(Laravel) on the cloud via Restful API.
PouchDB look good but that is out of option because it only support to sync with CouchDB.
What option do I have?
It's possible with dexie but not as complete as you get with pouchdb. The closest you come to a complete solution with dexie is using the Dexie.Syncable addon (https://github.com/dfahlander/Dexie.js/wiki/Dexie.Syncable.js) (not yet stable) and implement the backend from the following 2 backend sample implementations:
https://github.com/dfahlander/Dexie.js/tree/master/samples/remote-sync/
If you don't want to rely on Dexie.syncable, another solution would be to build your own sync addon based on the stable CRUD hooks that Dexie provides in it's default api:
https://github.com/dfahlander/Dexie.js/wiki/Table.hook(%27creating%27)
https://github.com/dfahlander/Dexie.js/wiki/Table.hook(%27updating%27)
https://github.com/dfahlander/Dexie.js/wiki/Table.hook(%27deleting%27)
Using those hooks, may log all local changes to a dedicated table for syncing with server when it goes online. This is what Dexie.Syncable is based on.

Offline Web Apps and database sync

I need to ask for some advice regarding offline web applications and database sync.
Offline Scenario
We have a web site (HTML5) that needs to operate in an offline mode for extended periods of time with complex data, the product owner does not want the data put into local storage.
We have two options as I see it;
Use javascript to detect if we are offlline and if so point the urls to a local web server that replicates the stack at the data center and writes to an offline db
◦Biggest stumbling block is how, on the first load if you are offline do you get the location (URL) of the local web server? i.e. user goes to www.xyz.com, but you are offline so
Question 1: how to redirect him to localhost.xyz.com via javascript for that first call
Point all calls at the client , offline or not to a wcf service that checks offline status at the NIC and redirects every web and service call to the correct place
◦seems like a big job,
Question 2: is there any product/ opensource project you guys know off that does this?
Sync Scenario
•They want to use MS sync framework
◦But they have many clients syncing to different database, so you either need 1 sync service per client or some way to identify who the client syncing is and point them to the correct place
◦Need to minimize locking during sync as other clients are using the same tables during sync
Question 3: can the sync framework be extended to even do this
Question 4: What other options exist for database sync on MS platform?
Thanks
If the user puts the URL into their browser, they are going to go that URL. There is no javascript at that point. You would only have Javascript once a page is loaded. You will have to search for a better solution.
Here is an idea: Users ALWAYS go to the local website, and if the remote site is up, then you redirect them.
In terms of MS sync I do not know what it is, so I cannot help you there.
Re What other options exist for database sync on MS platform: there is also SQL Azure Data Sync, a windows azure web service. It is actually built upon the Microsoft Sync Framework you refer to.
There is an example in the book "Programming Microsoft SQL Server 2012" by Leonard Lobel & Andrew Brust (MS Press) - chapter 13 covers building occasionally connected systems that incorporate SQL Azure Data Sync, Windows Azure and the Windows Phone 7 development platform. In the sample solution, on the back end, an on-premise SQL Server database is kept synchronized with a public facing SQL Azure database in the cloud using SQL Azure Data Sync. The cloud database is exposed using WCF Data Services (also hosted in the cloud by deploying to Windows Azure) and consumed via OData by a mobile client application running on a Windows Phone 7 device. The sample solution detailed in the chapter demonstrates how these technologies work to keep data in sync across on-premise SQL Server, SQL Azure databases in the cloud, and local storage on Windows Phone 7 devices.
Sync Framework do not lock tables when synching.
depending on what client database you want to use on the client, you can either use Sync Framework itself which works with MS databases (SQL CE, SQL Express,LocalDB,SQL Server, SQL Azure) or you can use the Sync Framework Toolkit
whichever platform you choose, i would suggest simply writing to the local store and synching it rather than dynamically choosing which store to use when.
for example, if you went offline and you wrote to the local store. then your network monitor detects you are back online and redirects you to the online service, what would you do with the data you stored locally? or you transacted online and you suddenly went offline, how recent/updated is the local store for you to actually starting working agaisnt it?
You could use Service-Workers to make the website work while users are offline. see: Making PWAs work offline with Service workers. This allows your website to work for the users if they are offline (they need to have internet at least once every 24 hours).
Service-Workers also allows you to detect when your user is offline or online, and you can for example use the IndexedDB to store your offline changes and then synchronize them when the user is online again.
I don't know about MS Sync.

Categories

Resources