I am working with deployd which uses mongoDB as a db on Ubuntu OS.
All databases of mongoDB are accessible from within mongodb shell but my question is when I create a new project with deployd I can store/read/modify records but this new database is not accessible from mongodb shell, how do i do that?.
Database files for this new project are stored within the application directory not in mongoDB default data directory.
Also what's the difference of mongoDB as a database within application and MongoDB as a global database for all applications.
Currently all collections are accessible using dpd object like
dpd.albums.get(inputParams, function(resultSet, err){ //handle result});
While I would like to access these collections using something like
db.albums.find(); //within mongod shell
It seems there are a few misconceptions here about the deploying with "deployd".
Firstly "deployd" depends on an existing mongoDB installation on it's deployed host or is otherwise configured to use a host on another server. So where "data files" are kept are generally a point of condifuration. All that "deployd" tries to do is start the "mongod" instance as it's own instance is started should the configuration be local.
No matter what you do, all of the options are available in configuration. There is a good sample in the documentation here:
var server = deployd({
port: process.env.PORT || 5000,
env: 'staging',
db: {
host: 'my.production.mongo.host',
port: 27105,
name: 'my-db',
credentials: {
username: 'username',
password: 'password'
}
}
});
As you can see the host and port settings are specified in the configuration of the application itself, so where you are not using the default "mongoDB" host and port then add them to the command line options, as in:
mongo --host my.production.mongo.host --port 27105
So even on the same localhost, note that the instance does not use the default 27017 port but a different one that you would need to specify when connecting.
Also see the mongo shell command documentation as well as the deployd documentation.
Related
I'm trying to follow the Flask-User documentation with MongoDB.
However, when I try to connect to my MongoDB Atlas, it's always writing to a "test" database, instead of the one I specify.
I have identified that it is because of the Flask-MongoEngine that is being used, as it mentions that
By default, Flask-MongoEngine assumes that the mongod instance is
running on localhost on port 27017, and you wish to connect to the
database named test.
However, even after inputting my URI details, I still keep writing to the test database.
Uri style connections are also supported, just supply the uri as the
hostin the ‘MONGODB_SETTINGS’ dictionary with app.config. Note that
database name from uri has priority over name.
app.config['MONGODB_SETTINGS'] = { 'db': 'project1', 'host': 'mongodb://localhost/database_name' }
My code
My configuration settings (albeit in another syntax) are as below
app.config['MONGODB_DB'] = '<redcated-database-name>'
app.config['MONGODB_HOST'] = 'mongodb+srv://<redcated-user>:<redcated-pw>#gapcluster-np4bu.mongodb.net/test?retryWrites=true&w=majority'
app.config['MONGODB_PORT'] = 27017
app.config["MONGODB_CONNECTION"] = False
Has anyone successfully used Flask-User with MongoDB Atlas before?
I cannot find anywhere to set the default connection URL for the mongo CLI. I want to be able to specify a particular username/password/hostname/database, which can all be specified as a URL. However, I want to just be able to type mongo instead of mongo "mongodb://…" in the shell.
I also don’t want the password to show up in /proc/«PID»/cmdline, but having it in a dotfile in my home directory is perfectly fine with me.
It doesn’t appear that ~/.mongorc.js allows specifying the default connection string. But I would expect such an option to be available because the mysql CLI supports ~/.my.cnf which allows you to specify username/password/hostname/database. So, where is this for mongodb?
EDIT: The solution has to work even if the mongodb at localhost is fully secured (no insecure local test database should be required—I thought this went without saying).
You can run mongo shell commands in ~/.mongorc.js. So you can just run the connect method in your ~/.mongorc.js:
db = connect("mongodb://username:password#host:27017/myDatabase")
When you run mongo it will first connect to localhost, then connect to the database passed to the connect method.
A MongoDB server must be running on localhost, otherwise the mongo shell will error and exit before trying to connect to the other DB.
Run mongo --nodb to get around needing to connect on localhost before connecting to whatever is defined in ~/.mongorc.js.
To directly launch mongo against a particular hostname/database/username/password without prompting for a password, without passing the password on the CLI, and without requiring an insecure database at mongodb://localhost/test, you can use this technique. Write a script file which does the connection for you and then launch mongo with the appropriate arguments. For example:
~/.mongo-do-auth.js
// https://docs.mongodb.com/manual/reference/program/mongo/#cmdoption-nodb
// https://docs.mongodb.com/manual/tutorial/write-scripts-for-the-mongo-shell/#mongo-shell-new-connections
//
// Run this with:
//
// mongo --nodb --shell ~/.mongo-do-auth.js
db = connect('localhost/admin', 'root', 'asdf123');
And then, simply launch it from the CLI to get an interactive session:
sam ~ # mongo --nodb --shell ~/.mongo-do-auth.js
MongoDB shell version: 2.6.12
type "help" for help
connecting to: localhost/admin
> quit()
Or, to run a script noninteractively, simply remove --shell and append your script. Consider a script:
s2.js:
print('connected to database ' + db);
To run:
sam ~ # mongo --nodb ~/.mongo-do-auth.js ~/s2.js
MongoDB shell version: 2.6.12
loading file: /root/.mongo-do-auth.js
connecting to: localhost/admin
loading file: /root/s2.js
connected to database admin
However, this requires a lot of work and invoking mongo with arguments. It appears that this is a limitation of mongo because no one has suggested any alternative which works as smoothly as the mysql CLI client’s ~/.my.cnf. This means that all shell scripts which directly invoke mongo will need to allow the the user to pass through --nodb and a path to a connection script instead of being able to rely on implicit per-user configuration.
I need help to set up two meteor instances in the same computer (this computer is used as a server). Each instance should run the same code (after build the meteor application) and work with a different mongo database.
I have readed and readed to try to found a guide o tutorial to do this but I have not found anything. How I can do this?
Thanks for your help!
You can do this the hard way and try connect to several mongodb instances via docker containers or just the easy way and associate each of your meteor instance with a single database inside your mongodb.
I know the naming is confusing because you may think "but mongodb is my database!?". But think this:
mongodb is your database process and for each application you can make mongodb associate a database.
You can do that like this:
1. open mongo shell of your production db (not your local meteor db)
mongo
2. In mongo shell, create for both of your apps a database and a database user
use app1db
app1db.createUser({
user: "app1dbuser",
pwd: "app1dbpassword",
roles: [{ role: "readWrite", db: "app1db" }]
});
use app2db
app2db.createUser({ user: "app2dbuser",
pwd: "app2dbpassword",
roles: [{ role: "readWrite", db: "app2db" }]
});
3. Start your meteor application instances with your databases (assuming local ip and defualt port for your mongodb)
app1
MONGO_URL="mongodb://app1dbuser:app1dbpassword#127.0.0.1:27017/app1db"
app2
MONGO_URL="mongodb://app2dbuser:app2dbpassword#127.0.0.1:27017/app2db"
The data created by the applications is stored in each db per app. App1 ahas no access to the db for app2 and vice versa.
I hope this helps to achieve whatever your goal is with this.
You could running the two instances on different ports.
You do something like this:
For the first instance meteor --port 3000
Second instance meteor --port 4000
They will use the same mongo db.
In one terminal, start meteor on port 3000, connected to a database called db1
export MONGO_URL=mongodb://localhost:27017/db1
meteor --port 3000
In another terminal, start meteor on port 4000, connected to a database called db2
export MONGO_URL=mongodb://localhost:27017/db2
meteor --port 4000
https://spring.io/guides/gs/accessing-data-mongodb/ - The example does not show connecting to Mongo DB usage.
default spring data mongo db is connect your localhost if you not declare any connfiguration properties in applicaiton.properties file
for example
launch mongodb server with mongod command and after launch your application and make any CRUD operation see log in your command prompt
if your application need special server uri or any configuration properties
add application.properties file this properties and configure
for example
spring.data.mongodb.uri=mongodb://user:secret#mongo1.example.com:12345,mongo2.example.com:23456/test
this configure your uri with colleciton names
and also declare host and port with this
spring.data.mongodb.host=mongoserver
spring.data.mongodb.port=27017
and also more properties knowledges(for example: username and password settings) here: https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html
connecting features here :
http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-connecting-to-mongodb
I'm following the telescope tutorial.
I created a /client/collections/myfile.js
I'm on localhost, but I'm launching Meteor with remote DB hosted on MongoHQ instead of using Meteor's local DB.
In this tutorial I'm told to insert a new post by opening the Mongo console.
$ meteor mongo
How can I:
$ meteor mongo (somehow connect to my remote DB to use the meteor commands in terminal
So that I can:
$ db.collectionname.insert({ stuff });
Or does this have nothing to do with "Meteor" in this case and I just use a Mongo shell outside of Meteor? The collection that I created in "/client/collections/collection.js" is this simply for telling Meteor which collection to push as a subset to the client?
I'd like to use the same DB ( remotely hosted with MongoHQ) for my localhost development, and my actual live dev.mysite.com so when I deploy to this dev site, anything I've done in the DB is also there and ready to go.
Assuming you had a username of username, a password of PASSWORD, a database named test, and a hostname of hatch.mongohq.com:
Connecting via the shell
$ mongo hatch.mongohq.com:27017/test -u username -p PASSWORD
Connecting via Meteor
$ MONGO_URL="mongodb://username:PASSWORD#hatch.mongohq.com:27017/test" meteor
Other notes
You should define your Meteor collections outside of the client directory so they can be used on both the client and the server. See this for more details.
You will find that connecting to a remote database is much slower than connecting locally, so it's generally not recommended for development.
Meteor creates a dev database for you when it starts. This also affords you the very helpful commands: meteor reset and meteor mongo, to reset, and connect to said database.
Initializing your database
Create a file on the server for initialization - e.g. server/initialize.js. When the server starts you can add users or other documents which do not yet exist. For example:
Meteor.startup(function() {
if (Meteor.users.find().count() === 0) {
Accounts.createUser({
username: 'jsmith',
password: 'password',
profile: {
firstName: 'John',
lastName: 'Smith'
}
});
}
});