D
David Berger
Guest
Modulus offers an integrated MongoDB solution. This guide will walk you through all the steps needed to create and begin using a Mongo database. CREATE A DATABASE Navigate to your user dashboard and select the "Databases" tab on the left. To create a new database, click the "Create Database" button. On this dialog, enter the desired label of the database, provider, and version. Note: The name is simply a convenience label and is not the actual name of the database within Mongo. Actual database names are created automatically by Modulus. You can optionally create a read/write user at this stage. If you do not create a user now, you must create one later in order to access your database. Once complete, the popup will update with information about your newly created database. The "Mongo URI" can be used to connect to your database from your application, IE it can be considered a connection string. The "Mongo Console" displays the command used to connect to your instance using the Mongo command line tool . This information can also be retrieved at any time on the "Administration" tab of your database dashboard. CREATE USING COMMAND LINE (OPTIONAL) You can also create a database using the Modulus CLI. This is done with the mongo create command. $ modulus mongo create Welcome to Modulus You are logged in as spiderman [?] Enter a database name: My Database Please choose a region: 1) 2.6.3 (joyent us-east-1) 2) 2.4.9 (aws us-east-1a) [?] region: 1 Selecting 2.6.3 (joyent us-east-1) [√] New MongoDB database My Database created. You can optionally pass in the your database label to the mongo create command. $ modulus mongo create "My Database" Welcome to Modulus You are logged in as spiderman Creating MongoDB database My Database Please choose a region: 1) 2.6.3 (joyent us-east-1) 2) 2.4.9 (aws us-east-1a) [?] region: 1 Selecting 2.6.3 (joyent us-east-1) [√] New MongoDB database My Database created. Once a database has been created, a user will need to be created as well. Use the mongo user create command to create a database user. $ modulus mongo user create Welcome to Modulus You are logged in as spiderman Please choose which database to use: 1) My Database 2) Other DB [?] database 2 Selected MongoDB database My Database. [?] Enter username: johnny [?] Enter password: five [?] Read only permissions? (yes) no [✓] New MongoDB database user johnny created. CONNECTING TO YOUR DATABASE Once the database has been created and a user has been set up, it can be connected to like any other MongoDB instance. USING MONGOOSE var mongoose = require('mongoose'); var db = mongoose.createConnection( 'mongodb://user
ass@proximus.modulusmongo.net:27017/enyrO4ma' ); USING THE NATIVE MONGODB DRIVER var MongoClient = require('mongodb').MongoClient; MongoClient.connect( 'mongodb://user
ass@proximus.modulusmongo.net:27017/enyrO4ma', function(err, db) { // Query the DB. } ); DELETING Databases can be deleted on the Administration tab on the database dashboard. All data will be destroyed and this action cannot be undone.
Continue reading...
Continue reading...