MongoDB is not showing collections when creating through Node JS - node.js

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.

Related

File structure for Node.js and MongoDB

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

Developing locally using express, mongodb and mongoose

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.

My localhost works but the heroku database doesn't

I'm using the remote database URL on my laptop and it works perfectly on localhost. When I upload to heroku, it won't save new users to the database. It's still connecting to the database to start the web application (I think). I see the 'session' storage increasing by one every time I visit the website online. And I can definitely create new users and do everything it's supposed to on my laptop.
I've tried changing versions of the database from mongodb 2.6 to 3.0. I've tried switching out versions of mongoose so that they're compatible with the version of mongodb (http://mongoosejs.com/docs/compatibility.html).
I've tried deleting node_modules and doing a fresh npm install.
Been debugging this for months and have probably put over 100 hours in to it with no solution. Can someone please help? I have no idea why the database would work on this machine but not the heroku server. All I've figured out so far is that the reason it's not working is the database won't create documents from heroku.

npm install mongpdb: How do I install mongodb in location: c:\mongodb

I've been following this tutorial : http://cwbuecheler.com/web/tutorials/2014/restful-web-app-node-express-mongodb/, and I don't understand what I need to do in order to get my app to use it. I've successfully installed everything with node.js up until to where the directions at
part4: mongodb
mongo
this call doesn't start the mongodb like it should. I've installed mongodb and saved in C:\mongo like the directions suggest but I can't access the mongo console. My guess is that I don't have it in the right path because when I try:
C:\mongo\
mongod --dbpath c:\node\nodetest2\data
c:\mongo\
use nodetest3
it throws:
"use is not recognized as an internal command...etc"
That leads me to believe that it's not installed correctly after I do:
npm install mongodb
Another troubleshooting idea I have is trying to correct the variable path, maybe? It's probably a much more simple issue about it's file placement/installation directory. I'm at a total loss at this point.
I want to reiterate that I've tried the directions in the other similar questions that have already been asked, but it doesn't seem to work. I think I need more detailed questions, where my experience level isn't assumed (I know that this is a beginner tut, and its database section is just little a above my expertise at this point.

Problems with the server connection MongoDB

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.

Resources