MongoDB Tutorial 1: Introduction
MongoDB Tutorial 1 : Introduction | Alternative control | Basic Window App | Buttons 1 | Buttons 2 | Mongo-Start
|
|
MongoDB Standalone UniServer 6-Carbo. |
MongoDB
Introduction
During the introduction tutorial we created several components (function) to run MongoDB with or without authentication.
This follow on tutorial uses these components to run MongoDB in standard mode (no authentication) in other words it runs in a trusted network. From Mongo’s Wiki this is a recommended way to run MongoDB
Objective of this tutorial is to create a portable standalone server. This server is controlled using a windows interface implemented with WinBinder. Prime objective is to introduce WinBinder a follow up tutorial will show how to integrate the finished server into Uniform Server’s architecture.
Tutorial starts with newest version of MongoDB currently 1.4.4 and builds around this core.
Tutorial Plugin Download
Download the tutorial plugin and extract to any folder for example mongo_temp
For download details see MongoDB Introduction (Main Start page)
MongoDB Download
- Create a folder mongo_new
- Download latest version of MongoDB from download site
- Note: You want the Windows 32-bit version.
- Save to above folder and extract.
Folder structure looks like this delete and rename folders as shown. mongo_new mongodb-win32-i386-1.4.4 mongodb-win32-i386-1.4.4 - Rename to mongodb_1 bin include - Delete lib - Delete |
mongo_new mongodb_1 bin |
That gives a working structure core binaries are in folder bin and licences are retained and located in top folder (mongodb_1).
Inside folder mongodb_1
- Create a new folder alt_control
- From folder UniServer\usr\local\mongo_tutorial\bin copy file to bin
- config_no_auth.ini
- pskill.exe
- uniserv.exe
- Create a new folder control
- Copy contents of folder UniServer\usr\local\mongo_tutorial\WinBinder_1\a_test to folder control
- Copy folder UniServer\usr\local\mongo_tutorial\data to top folder mongodb_1
- Copy folder UniServer\usr\local\mongo_tutorial\WinBinder_1\php to top folder mongodb_1
- Copy folder UniServer\usr\local\php to top folder mongodb_1
- Create a new folder z_temp
- Copy file UniServer\usr\local\mongo_tutorial\Cheat_folder\mongo_db_inc.php to z_temp
Folder file structure
mongodb_1 - Top level folder alt_control - Alternative control folder (empty) bin - Folder mongo.exe mongod.exe mongodump.exe - Mongo core components mongoexport.exe mongofiles.exe mongoimport.exe - Mongo core components mongorestore.exe mongos.exe mongostat.exe - Mongo core components pskill.exe uniserv.exe - Uniform Server Utilities config_no_auth.ini - Configuration file added for tutorial control - Tutorial work area mongo_tutorial.bat - Batch file to run mongo_tutorial.phpw mongo_tutorial.phpw - Starting point Windows application winbinder - Folder containing Winbinder include scripts images - Folder contains utray.ico use your own data mongodb - Location of Mongo generated databases php - PHP folder php.exe - Runs php5ts.dll this dll contains PHP 5.3.2 php5ts.dll - common extensions and WinBinder mongo_tutorial_cli.ini - PHP CLI configuration file loads php_mongo.dll php\extensions - php extensions folder php_mongo.dll - Mongo php extension (PHP driver) z_temp - tempory will be deleted mongo_db_inc.php - Main functions
Test script 1
At this stage we want to check PHP runs correctely and picks up extension.
Navigate to folder control
Create a new batch file test.bat with the following content: TITLE UNIFORM SERVER - window_tutorial COLOR B0 @echo off cls cd ..\php php.exe -c mongo_tutorial_cli.ini ..\control\test.php pause EXIT |
|
Create a new test script test.php with the following content <?php phpinfo(); ?> |
To run script double click on test.bat a large amount of data is output. From the top scroll down until you see something like output on right. This confirms Mongo dll has been loaded |
MongoDB Support => enabled Version => 1.0.7+ Directive => Local Value => Master Value mongo.allow_persistent => On => On mongo.auto_reconnect => On => On mongo.chunk_size => 262144 => 262144 mongo.cmd => $ => $ mongo.default_host => localhost => localhost mongo.default_port => 27017 => 27017 mongo.utf8 => 1 => 1 |
Incorrect paths
Moving scripts around to different folders is generated to kill them For example run mongo_tutorial.bat error message produced on right. This is not a real issue |
The system cannot find the path specified. 'php.exe' is not recognized as an internal or external command, operable program or batch file. Press any key to continue . . . |
Edit file mongo_tutorial.bat
Change this path
cd ..\..\php php.exe -c mongo_tutorial_cli.ini ..\mongo_tutorial\a_test\mongo_tutorial.phpw
To the following
cd ..\php php.exe -c mongo_tutorial_cli.ini ..\control\mongo_tutorial.phpw
Rerun the batch file and a window with a few buttons will greet you.
This confirms WinBinder is working correctly.
Note:
What’s important all functions in mongo_db_inc.php use constants. We only need to change these for the functions to work correctly. More importantly there are only a few to change. That’s jumping the gun a little and will be covered later.
Summary
The above gives us a working environment.
We are not interested in the windows thingy until a working alternative control is in place. This is needed to test and debug the windows application.
Next page covers alternative control. Target is a real application hence once covered will not change.