MongoDB run locally or through Atlas? - javascript

Is it better to learn MongoDB through MongoDB Atlas or to have MongoDB downloaded locally?
When I go to https://docs.mongodb.com/manual/tutorial/getting-started/ I see there are two options for downloading MongoDB. I'm guessing it doesn't matter which one you download but if there is a better option, it would be nice to know.

When you're getting started, i suggest the quickest option. Knowing how to configure/install a local instance of Mongo is certainly important, but it can sometimes be a drag and prevent you from the more 'enjoyable' parts of learning a new technology.
I personally recommend going with Atlas at first. After you've seen enough mongo to get familiar with the shell commands, take a swing at installing it locally.

Related

Using a database for a Node.js application that runs in the terminal

I'm currently writing a program that is a To-Do list that just runs locally on my machine in the terminal screen(written in node.js, no extra dependencies). I've set up everything and it works totally fine, but I have never actually used any databases other than just session cookies on the browser. What would you all suggest I use when all I want to do is learn how to store some simple data in a database and then be able to manipulate it in the same fashion.
Any help would be greatly appreciated on this one! I'm really just looking for suggestions on a good database, as well as a bit of guidance on the best way to use that particular technology. I'm familiar with SQL and NoSQL databases, but like I said, I have never even used one on an actual application.
Thanks in advance.
In my view, You can use mongodb which is easy to configure and manipulate data. It helps you to work on json objects directly from database. Use express to create your RESTful endpoints and exposed data. Sometime back i use it for angular application, repo link is below for your reference :
AngularJs, ExpressJs, MongoDB application
Hope this helps.
Cheers
You can use sqlite which provides a good SQL API but keeps things very simple by simply using a file on your disk and accessing it through code directly in your application. You don't need to start another server and take care of configuring it.
For a simple To-Do list that should be more than adequate for storing your data whilst keeping your configuration simple and easy.
Here's a tutorial on how to set it up:
http://www.sqlitetutorial.net/sqlite-nodejs/
You'll essentially be using the sqlite3 npm package: https://www.npmjs.com/package/sqlite3
That page also comes with brief usage instructions.
Nodejs has client libraries for database interaction
Ex.
For SQL database:
postgresql : https://github.com/brianc/node-postgres
For NoSQL db:
mongodb : https://github.com/Automattic/mongoose
You can also create pool of db connections

Node.js - Taking it public?

I'm learning how to program in Node.js, and so far I've been able to run it using my computer as a server, and log in through an IP address:8080 from other computers on the same router. But for the life of me, I can't seem to find any tutorials or anything for taking it public. E.g using my laptop from work to connect to the server hosted at home. I've searched free servers and am completely mixed up on SSH keys and github requirements and stuff with a bunch of others. I'm really mixed up.
I'm also thinking it would be much simpler (and 100% free on monthly payments) to buy my own hardware and run my own servers? Any tutorials on node.js hardware set ups?
Please help, I'm completely confused.
EDIT
I seem to have been a bit unclear. I'm going to use node.js to make games/apps with logins. When you "login" you automatically login to the server also. Not only from "work to home", I meant completely public as a multiplayer game.
One easy way to setup a node server for free is using AWS Free Tier.
Once you follow that link and setup a server...
You can follow along with this tutorial to get your server up and going, install node, install mongodb and even make an app that will run on the live server.
Run throgh this tutorial
How I installed node on my server,
Personally I have a VPS from Bluehost. This cost me about $120 a month but lets me do whatever I want with my server. By whatever I want I mean install whatever I want...
I have npm install,
I installed node.js globally.
I installed mongoDB.
I can run mongodb applications from anywhere and connect them to the MongoDB running on my server.
Having a VPS can come in handy as you can see... I suggest AWS free tier. Learn how to install all the things you want. Play with it. Break it and start over.
But when your done with all of that...
Be a Jedi Master!
Node doesn't have any specific hardware requirements or configuration. And can be hosted on anything.
I guess you don't have a dedicated ip address. So, your question seems to be all about network, routing and dealing with NAT. If you're not familiar with those, it might be not a bad idea to use external hosting.
But if you want to give it a try, this might be helpful - https://superuser.com/questions/121435/is-it-possible-to-host-a-web-server-from-behind-a-nat
Besides hosting your own hardware, there are 2 options for what you describe.
One, use a portforwarding tool to make your home server accessible from your work, for example ngrok.
Two, deploy your node.js app to an online platform, for example OpenShift or Heroku. Most of these platforms have a low-performance free options.

How can meteor detect mongoDB changes? [duplicate]

I had been wondering about knowing mongoDB changes instantly for a while and best solution that I have ever seen, is tailing mongoDb logs and I just had given wondering up till met Meteor.
When there is a changes on mongoDB somehow(through Meteor or directly), Meteor understands the changes instantly and apply them. We could see it on publishing changes or observing(observe or observeChange) changes.
I guess that, Meteor could understand it by tailing mongoDB logs as the best solution that I have ever seen suggests. But this assumption also make me ask that, Meteor can run with a mongoDB running on different host and if the way that meteor knows MongoDB changes instantly is tailing logs, how could Meteor tails logs of mongoDB running on different machine(different host) and handle changes? Tailing on different host requires painful things and I think Meteor does not follow this way.
I think tailing logs is not my answer because of this question.
I am curious about this knowledge. Cause, I think that, if I have it, I could use it on my other works without Meteor.
So, how could really Meteor knows mongoDB changes instantly? And I wanna ask once again; what would be the best way to know about mongoDB changes instantly?
Thank You!
Yes you are right this is from new new oplog tailing functionality. Meteor pretends that it is mongodb in a replica set and it tails mongodb's operation logs for collections it is monitoring.
Usually databases need multiple servers so that they can stay up in case one fails. MongoDB has this functionality in a replica set.
So this is where meteor comes in. Meteor pretends to be a mongodb replica database so when any data changes on this operations log for other copies to see, Meteor knows that data has changed and can push this new data down to the client instantly.
Usage in production
You can use a different mongo database with this new functionality as you set MONGO_OPLOG_URL. You will need to set mongodb as a replica set first so that the operations log is enabled
This was a very recent introduction put in just last week in version 0.7 you can see the blog post about it below
More links about it:
https://www.meteor.com/blog/2013/12/17/meteor-070-scalable-database-queries-using-mongodb-oplog-instead-of-poll-and-diff
https://www.youtube.com/watch?v=_dzX_LEbZyI
https://github.com/meteor/meteor/wiki/Oplog-Observe-Driver

Connecting to couch db from a webpage

I used to use mysql databases and a php backend for my web applications. Now that I am diving deeper into the the javascript world I am looking for a more compatible way to store my data. I like the idea of writing everything in one language, and javascript seems to be capable to make that job.
I started reading about couchDB and the JSON/javaScipt approach seems to fit perfectly to my needs. My question is now, which would be a convenient way to connect to the database from my pages.
I found this post, which explains how to connect to a couchDB directly from a client-side javascript using a library called couch.js. The post is quite a few years old and the library I cannot find anywhere in the web. So I am asking myself If this approach is still up to date.
I was thought that one important reason for using a server backend is to provide a security mechanism to protect the database authentification process. So: Is it generally secure to save an (encrypted) db pwd in a client side script?
So what I am looking for is a quite simple way to access and store json-like data from webpages. Are there any suggestions?
The hosting of the production solution should also be not that difficult and in the end not expansive, since it's rather meant for smaller projects at the moment.
If the post does not fit to the forum, let me know a better place for it..
I have been using the CouchDB jQuery Plugin for development. At first I was hesitant as well to use it due to most documentation being at least a few years old. So far it has worked really well and been very easy to use, especially if you are familiar with JavaScript/jQuery.
...
You can get the plugin from Github
CouchDB jQuery Plugin
Or you can save it directly from Futon:
http://localhost:5984/_utils/script/jquery.couch.js (where local host is your IP and 5984 is the port CouchDB is on)
Whatever you do, make sure you enable CORS on your database. There are instructions on the Github Readme page, or this script is super useful and easy to use through npm.
...
Documentation can be found here.
This reference has also been very useful for me.
...
Good luck!
I just released Slouch, a JavaScript client for CouchDB that can be used in both the browser and in node. I hope this helps!

Questions about node.js

I've been trying to do some research on node.js and Mongodb and have a few things that need clarifying.
I'm trying to query Mongodb from the web and want to use JavaScript because I'm familiar with the language, plus it makes sense because that's what Mongodb uses in the command line interface.
It seems that I'll have to use node.js to query mongo from the web, but what I can't find info on is a way to tell my node.js server what I want to query, from the web.
If someone can point me in the proper direction ( reading material, how to, examples) that would be awesome.
Here's some articles I used...
http://css.dzone.com/articles/nodejs-and-mongodb-beginner%E2%80%99s-0
http://srirangan.net/2012-02-node-js-and-mongodb-getting-started-with-mongojs
http://mattkopala.com/blog/2012/02/12/getting-started-with-nodejs/
I found Mongoose to be the best Node.js MongoDB library (the creator of Mongoose actually now works for 10gen, the company behind MongoDB).
Besides a lot of good examples on the official Mongoose website, you can find lots of other resources:
http://pixelhandler.com/blog/2012/02/09/develop-a-restful-api-using-node-js-with-express-and-mongoose/
http://backbonetutorials.com/nodejs-restify-mongodb-mongoose/
http://dailyjs.com/web-app.html (how to build an app from the start, multiple lessons)
One of the most important things I like about Node.js and MongoDB (Mongoose in my case) is that you are writing the query commands sometimes exactly like you write them in the MongoDB shell.
P.S. Last but not least, checkout the videos from 10gen related to Node.js and MongoDB, there are lots of them (and people using Node with Mongo in production): http://www.10gen.com/presentations#programming_lang__javascript_nodejs

Categories