Using MongoDB locally (electron)? - javascript

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.

Related

Local MongoDB implementation for Electron App

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?

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.

How can I get the URL of the currently connected MongoDB database from inside Meteor?

Background: I am preparing a Meteor app for production, and in particular I am adding server logging. To do this I am using winston with the MongoDB plugin. This requires the URL to the database. These databases are different between production and development environments so I want to set it programatically.
I am trying to avoid running forking a script to run
# meteor mongo --url
I also don't have access to $MONGO_URL on the development server (it doesn't appear to be set, for instance in process.env.MONGO_URL)
I expect that there is something like below, but I couldn't find this in the documentation or via Google.
Meteor.MongoDB.getURL();
Sorry if this is something really obvious...it feels like it should be easy.
This works server side. It needs Meteor 1.0.4+ (I think. Added somewhat recently):
var collection = new Mongo.Collection("some_collection");
console.log(collection.rawCollection().db.options.url)
Keep in mind you can have multiple MongoDB's (at least at the collection level, or this is how the design is at least, anyway) so you need to query a collection for its Mongo URL.
I found the answer.
As mentioned in the question, the MONGO_URL environmental variable was undefined, but that appears to be either a misunderstanding or a bug in my IDE.
When I logged the value of process.env, I saw that MONGO_URL was indeed set, so I've used that.
In short:
process.env.MONGO_URL

Two-way communication between Meteor and Node

I am building a Node app that talks to an Xbee over serial and reads/controls several sensors/relays that are also Xbee equipped. I would like to use Meteor for the user interface and data storage with the Node app simply sending sensor updates and controlling the relays when triggered by the Meteor app. What would be the proper way to communicate between the Node and Meteor app? I know I can use a Node DDP client to insert sensor readings to the Meteor app. The part I am having problems with is sending commands from Meteor to the Node app to control the relays. I simply need to send a command that will execute certain code on the Node app to switch the relays. Maybe this is a simple question, but I'm not sure of the best way to accomplish this. Thanks in advance for any input.
You could just use Mongo as your point of integration. Each XBee device could just be a mongo document.
{
address: 'xbeeaddress',
relay1: 'on'
}

flat file database system especially for javascript

Is there any flat file database system that works well with javascript such as one in JSON format or similar. I have heard about mongodb, couchdb and others but it seems whole setup of it must be installed on the computer.
Of course, I can't use sqlite beause I think I won't be able manipulate it via javascript and I don't want to use any server-side language for my small apps.
I searched on google as well. Basically I am just looking for flat file database system that I can put in javascript app's folder (meaning portable database and app) and be able to use it anywhere, for example on some other computer without having to install any dependencies ? Does such portable flat file database exist out there ?
How about PouchDB? It's intended for web apps that cache data offline.

Categories

Resources