Storing information in meteor mongodb collection from outside nodejs file - node.js

I've got a mongodb collection that gets started with Meteor that I would like to connect to and edit from a nodejs file outside of meteor. From my understanding when I start meteor, I can open another terminal and type meteor mongo and it allows me to connect to the running mongodb instance that meteor is running. But how can I connect to this from a nodejs file? And add items to a collection in a database? What sort of security/authentication do I have to go through if any? (I don't remember having to set up a username/password for the mongodb, it just starts when meteor starts)

When running meteor locally, the mongodb is running on port 3001. There's no security or authentication, you simply have to connect to 127.0.0.1 port 3001, and then access the meteor database.

Related

Procedure for creating a database locally using mongodb

I've connected to mLab using MongoClient.connect, but now I want to create a local database rather than use mLab. I've tried changing the URL to "mongodb://localhost:27017/mydb" to create a database locally as suggested, but I'm getting a failed to connect to server error. Is there anything I should install? Or am I just missing something?
First, install your mongoDB server:
https://docs.mongodb.com/manual/installation/
After that, you should be able to start your local mongodb server:
sudo service mongod start //in case of linux
Here the docs to start the mongodb server
Then, you will type mongo and the client command line will start.
And when typing use yourDatabase, mongo will create the database if
it does not exist.
Then, your server will be up, and the database created. Anyway, check the docs if you need the guides for windows or other systems.
First you need to understand how server works and mlab works. mLab is a company who provide database as a services. Means you no need to handle server hurdles, they take care server , backups , infrastructure etc. They provide mongodb server , You just need to create database on mongodb server's and use them.
Now comes to main points.
If you want use mongodb on your local system then you first need to install mongodb on your local system and then connect it.

database settings in reactioncommerce

I installed reactioncommerce and I would like to access the database settings to check the name that the installation created in my mongodb server. I checked the information on the website but I cannot find any details about it.
in mongodb: when I use "show dbs" in mongo I cannot see any new db in my server. on the other hand, the demo application is running on port localhost:3000.
any guidance appreciated.
well it seems the mongodb for meteor always runs at one port above the meteor port. So by default the db is running at 3001. While you can have Meteor running you can also run meteor mongo and get a db console that way.

How to access mongodb spawned by meteor app on a remote server?

I have a meteor application with mongodb running on one of my systems. I want another application running on a different system to be able to access the mongodb that is spawned by my meteor application.
How can I accomplish this because by default the mongodb bind ip is localhost, so it's not accessible from outside.
Not recommended but you can disable the restriction of MongoDB that can be accessed only via localhost.
See: http://www.mkyong.com/mongodb/mongodb-allow-remote-access/
if your service is on the same server, then use the localhost address:
Meteor tends to expose the mongodb at its adress +1
(if meteor is on port 3000, mongodb is on port 3001)
then your service can access it at localhost:3001
If you want to access from another server, then you need to change the mongodb config to expose the port to the outside (probably also setup some firewall rules to only give access to your other server etc...)
and then use the suggested above
MONGO_URL=mongodb://hostname:port
ideally deploy your mongodb securely somewhere and plug Meteor an any other app needing it to it via the connection string.

Two nodejs server connect to one MongoDB server at the same time

Is there any problem if I use two nodejs server connect to one MongoDB server at the same time?. Can this way create any read/write issue on mongo instance?.
The same question for another case: One nodejs server connect to two MongoDB server at the same time?

Run mongodb from remote server

I am new to mongodb and want to know about connecting to remote server. I have mongodb running on remote server. I want to access the mongo database from another server and perform all the operation. How can i do that. I am using node.js with mongodb. Please help me how can i establish the connection.
You can use the following library for node:
https://github.com/christkv/node-mongodb-native
If you want a tool to access the database, you can use:
MongoHub (for Mac) & MongoVUE (for Windows)
Good luck!

Resources