I am currently learning Node.js and MongoDB for an open source project.
How should they be located in relation to one another as far as their source files?
MongoDB defaults the data folder to root, but I have MongoDB itself installed in a sub directory. Node.js in installed in yet another sub directory on same drive.
Do they need to be located in same location, or does that not matter?
Thanks for any clarification, didn't see this anywhere in the tutorials I am learning from.
No. It doesn't matter.
When you use the mongo client to connect to the mongoDB server, you already specified a host & port of that mongodb instance (this is what matters).
To use mongoDB in nodeJS: http://mongodb.github.io/node-mongodb-native/2.2/api/.
Hope it helps
Related
I'm currently making an app using express, mongodb and mongoose, and I'm running it locally on my machine. My problem is that if I'm not connected to the internet the app won't run at all due to the app not being able to connect to mongodb server.
I thought that if I ran the mongodb server locally on my computer along with the app then I wouldn't need an internet connection, or is my understanding wrong?
Any help would be much appreciated.
The answer is: yes.
If you install MongoDB locally then you won't need internet connection to access it.
Make sure that your connection string contains "localhost".
Also, make sure that you don't need anything else on the internet, and that you run npm install while you are connected to the internet, or otherwise your dependencies (like mongoose) won't get installed. After they are installed they can work without the internet connection just fine - if your database is on localhost.
Also, make sure that your local MongoDB server is running. You can run:
mongo test
in the command line to see if you can connect to a local database.
You're in the right path !
Here's the thing, you need to get yourself a copy of MongoDB, you can download and install the suitable version to your system from here.
Now you need to configure MongoDB in your in your path so you can launch it when you is or simply add it a process that will launch when your system starts.
In order to configure please choose the suitable conf to your system :
Windows.
Linux.
macOS.
Then, before running your application, make sure MongoDB is running in the background ad service or daemon and then simply launch your application.
So I had a directory named data, I ran mongod --dbpath path_to_data, it worked and gave me a port. I created a Node JS application, inserted some dummies data to the MongoDB through the same port using the mongodb package. When I ran the app, it worked fine. I even had it printed out through MongoClient find() method. However, when I opened the mongo shell and typed show collections, there wasn't any collections that showed up.
I had the exact same thing happen to me when I first installed Mongo on my Windows 10 machine. I'm not sure exactly what caused the problem, but it cleared up after I uninstalled MongoDB and then reinstalled it as a Windows Service.
I found the solution. Apparently, if you set up the database path as mongod --dbpath something/another/projectfolder/data, then at your node js file, connect using the path something/another/projectfolder. Don't include the data there.
I am trying to run a web application locally that uses grunt and mongodb. The app allows users to upload information which they can then view in their gallery.
started mongodb with mongod --port 3000 --httpinterface
(As mentioned in the comments, I have tried running it without the --httpinterface as well)
browsing to 127.0.0.1:3000 gives a page with only the text "It looks like you are trying to access MongoDB over HTTP on the native driver port."
browsing to localhost:3000 loads my application
the application sends data over 127.0.0.1, and it is not going through
It seems very relevant to what is going on in this question.
I hope this will not be considered a duplicate, because after finding that question I tried to work through the answers offered without success. If I was able I would have tried pursuing this issue in the comments there.
Following the answers on that question I tried running mongo with a config file without success (no config file existed beforehand, I tried to create one with the sample offered on the mongo website but it rejects it). I also tried deleting the lock files and repairing mongo. Nothing has changed.
It's probably worth mentioning that the application I'm working with is an existing, sparsely documented project that was given to me for a school assignment. It is far more complicated than anything I have ever worked on and I am very unfamiliar with tools like mongo.
I am creating a NodeJs Desktop application using node-webkit and right now using MongoDB as a database.
I want to distribute it as an executable where users will be able to use the application without installing the database by utilizing their own copy of local DB.
Is there a way i can make a local copy for their DB during the installation.
If it is not possible in MongoDB, what other DB should i use?
well its based on your data needs, if you have large set of data you should use mongoDB otherwise there are lots of databases for your NWJS app. check this link https://github.com/nwjs/nw.js/wiki/Save-persistent-data-in-app some of them are good enough to hold big data. but personally i prefer sqlite3 with NWJS(there is a lot of hustle to install it for NWJS) sqlite can work with large data check this page for more info.
if you are going with mongoDB then you should download the the zip not the installer and pack it with your installer the you should be good to go.
by default mongoDB stores its data in /data/db but you can change it to your preferred location
I am a beginner in MongoDB and MAC OS X. I have a web based project using Node.Js-JadeExpress-MongoDB.
After 3 weeks, finally I can integrated JadeExpress and Node.js via terminal, but the problems still come with MongoDB server. Each time i want to connecting a MongoDB server via terminal, i have to create a file bashrc by vim editor.
Inside that, I have to put this code :export PATH=<mongodb-install-directory>/bin:$PATH .
I use this tutorial as a reference:
http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/
Does anyone know what I have to do to connecting to the MongoDB server efficiently?
If you are not very familiar with command line interface then I would say just take all the mongodb binaries from the mongodb/bin/ folder and put them in /usr/bin/ folder. So that you don't have to modify PATH at all.
Not the most efficient way but will solve your problem.