487
edits
(New page: {{Nav MongoDB Plugin Design}} '''''MongoDB''''' == Introduction == MongoDB is a server in its own right hence instead of a plugin purhaps a stand alone version is the best way to go procee...) |
(Punctuation and grammatical changes; some clarification.) |
||
Line 2: | Line 2: | ||
'''''MongoDB''''' | '''''MongoDB''''' | ||
== Introduction == | == Introduction == | ||
MongoDB is a server in its own right | MongoDB is a server in its own right, so instead of defining it as a plugin, perhaps a stand alone version is the best way to proceed. | ||
The other plugins are in reality separate applications, and when I refer to an application, it is a generic term and could be one of the above. | |||
This tutorial’s sole purpose is to create a generic set of components (functions) to implement either of the above. | This tutorial’s sole purpose is to create a generic set of components (functions) to implement either of the above. | ||
== Control == | == Control == | ||
From a control point of view we need to start and stop MongoDB in either development or production mode. In other words control architecture must cater | From a control point of view, we need to start and stop MongoDB in either development or production mode. In other words control architecture must cater to no authentication and authentication respectively. | ||
Uniform Server users will be familiar with using default name and password of '''root''' | Uniform Server users will be familiar with using default name and password of '''root'''. For consistency, the same defaults will be used for the MongoDB plugin. | ||
== MongoDB == | == MongoDB == | ||
Interestingly MongoDB allows you to start the server with or without authentication. This is configurable using a configuration file or | Interestingly, MongoDB allows you to start the server with or without authentication. This is configurable using a configuration file setting or via a command line parameter. | ||
For scripting a configuration file is the preferred method of starting MongoDB server. | For scripting, a configuration file is the preferred method of starting MongoDB server. | ||
'''''To read a file'':''' | '''''To read a file'':''' | ||
Line 25: | Line 23: | ||
We want to run MongoDB in either one of two modes. This can be accomplished using two command lines and two separate configuration files as follows: | We want to run MongoDB in either one of two modes. This can be accomplished using two command lines and two separate configuration files as follows: | ||
=== Starting Server === | === Starting the Server === | ||
{| | {| | ||
|- | |- | ||
Line 42: | Line 40: | ||
bind_ip = 127.0.0.1 # Localhost | bind_ip = 127.0.0.1 # Localhost | ||
port = 27017 # Port to use | port = 27017 # Port to use | ||
noauth = true # | noauth = true # no authorization | ||
verbose = true | verbose = true | ||
</pre> | </pre> | ||
Line 50: | Line 48: | ||
bind_ip = 127.0.0.1 # Localhost | bind_ip = 127.0.0.1 # Localhost | ||
port = 27017 # Port to use | port = 27017 # Port to use | ||
auth = true # authorization required | |||
verbose = true # to disable, comment out. | verbose = true # to disable, comment out. | ||
</pre> | </pre> | ||
|} | |} | ||
With the exception of dbpath and auth all parameters are default values. | With the exception of dbpath and auth all parameters are default values. | ||
Strictly speaking there is no need to include default parameters | Strictly speaking, there is no need to include default parameters. They are included because they may change later. Also they serve as a quick reference. | ||
'''''Note'':''' Parameter '''dbpath''' uses a relative path. This inherently makes the server portable. | |||
=== Mongo-client | === Mongo-client Access === | ||
To access server using the mongo-client requires slightly different command-line formats as shown blow. | To access the server using the mongo-client requires slightly different command-line formats, as shown blow. | ||
'''''Note'':''' Database we want to initially connect to is '''admin''' | '''''Note'':''' Database we want to initially connect to is '''admin''' | ||
Line 86: | Line 82: | ||
=== Stopping the Server === | |||
=== Stopping Server === | |||
Stopping the server requires access to the Admin database. Again to access server using the mongo-client requires slightly different command-line formats as shown blow. | Stopping the server requires access to the Admin database. Again to access server using the mongo-client requires slightly different command-line formats as shown blow. | ||
Line 106: | Line 101: | ||
</pre> | </pre> | ||
|} | |} | ||
I have show two methods for selection the admin database either | I have show two methods for selection the admin database, either by specifying it on the command-line or by getting the help method db.getSisterDB('admin') to select it. | ||
'''''Note'':''' | '''''Note'':''' | ||
If the server is running as a visible command line process you can use Ctrl c to shutdown the server. However server will be run with | If the server is running as a visible command line process you can use Ctrl-c to shutdown the server. However, the server will be run with its command window hidden. The only way to shutdown server is via the client. | ||
'''''[[#top | Top]]''''' | '''''[[#top | Top]]''''' | ||
Line 136: | Line 131: | ||
A user must exist in the admin database before attempting to use authentication. | A user must exist in the admin database before attempting to use authentication. | ||
== Admin name and password == | == Admin name and password == | ||
The admin database is a database containing data for running and administering the entire MongoDB server. | The admin database is a database containing data for running and administering the entire MongoDB server. | ||
Adding a user name and password is easy | Adding a user name and password is easy. Let's assume a fresh install of Mongo: | ||
* Start MonoDB server | * Start MonoDB server | ||
Line 156: | Line 150: | ||
</pre> | </pre> | ||
|} | |} | ||
Authentication takes immediate effect. Further actions require authenticated access | Authentication takes immediate effect. Further actions require authenticated access. With the current connection you can use explicit authentication by entering this line: | ||
<pre> | <pre> | ||
db.authenticate("name", "password") | db.authenticate("name", "password") | ||
</pre> | </pre> | ||
'''''Note 1'':''' Uniform Server defaults name='''root''' password='''root''' | '''''Note 1'':''' Uniform Server defaults are name='''root''' password='''root''' | ||
'''''Note 2'':''' Currently there is no way to create a user with restrictive privileges. Hence only assign a single user to the Admin database. | '''''Note 2'':''' Currently there is no way to create a user with restrictive privileges. Hence only assign a single user to the Admin database. | ||
=== Adding users and assigning databases === | === Adding users and assigning databases === | ||
This will come as a surprise especially if you are a MySQL admin. Creating a new user and assigning a database is similar to the above. | This will come as a surprise especially if you are a MySQL admin. Creating a new user and assigning a database is similar to the above. | ||
Line 185: | Line 178: | ||
To display existing users for a database | To display existing users for a database | ||
Select database and type this command: | Select the database and type this command: | ||
<pre> | <pre> | ||
db.system.users.find() | db.system.users.find() | ||
Line 191: | Line 184: | ||
=== Changing Passwords === | === Changing Passwords === | ||
If a user already exists all that is required is to run addUser to change their password. | If a user already exists, all that is required is to run addUser to change their password. | ||
Hence to change the default Admin requires: | Hence to change the default Admin requires: | ||
<pre> | <pre> | ||
Line 198: | Line 191: | ||
</pre> | </pre> | ||
== Command-line parameters == | == Command-line parameters == | ||
To view command-line parameters accepted by command-line tools | To view command-line parameters accepted by command-line tools: from a command prompt, type the application name followed by –help | ||
For example: | |||
=== mongod.exe --help === | === mongod.exe --help === | ||
Line 278: | Line 272: | ||
and will exit after unless --shell is specified | and will exit after unless --shell is specified | ||
</pre> | </pre> | ||
== Summary == | == Summary == | ||
Development mode (no authentication) is really a fallback mode only used to gain access to the server should something drastic happen. It can be used for production, but ''only'' on a trusted network. | |||
A production server (authentication) in the context of Uniform Server means the server is pre-configured with a default name/password this must be the first thing a user changes. | A production server (authentication) in the context of Uniform Server means the server is pre-configured with a default name/password; this must be the first thing a user changes for security purposes. | ||
This admin user will create new users and | This admin user will create new users and assign them to databases. More specifically, each application on the server should be assigned a unique database user. | ||
This page serves as a reference providing enough detail to create components (functions) required for our application. | This page serves as a quick reference, providing enough detail to create components (functions) required for our application. | ||
If you wish to follow this tutorial download and install tutorial plugin as explained on the [[MongoDB Plugin Design: Download | '''next page''']]. | If you wish to follow this tutorial, download and install the tutorial plugin as explained on the [[MongoDB Plugin Design: Download | '''next page''']]. | ||
'''''[[#top | Top]]''''' | '''''[[#top | Top]]''''' |