Tags

,

  1. There are 2 file versions of MongoDB that you can use such as using the msi and the build archive:
    For the latest msi version go here https://www.mongodb.org/downloads
    For a specific Build Archive just go here http://dl.mongodb.org/dl/win32/x86_64
  2. Configuration file
    Next create a mongodb.conf file inside mongodb folder and follow the basic snippet below.
    MongoDB need a folder (dbpath) to store its data. By default, it will store in “C:\data\db“, create this folder manually.
    MongoDB won’t create it for you. You can also specify an alternate data directory with –dbpath option.
    Next, create manually a log file mongo.log for your mongo under C:\mongodb\log.

    ##store data here
    dbpath=C:\mongodb\data
    
    ##port
    port = 27017
    
    ##all output go here
    logpath=C:\mongodb\log\mongo.log
    logappend=true
    
    ##log read and write operations
    diaglog=3
    ...
    
  3. Run MongoDB server
    C:\mongodb\bin>mongod --config C:\mongodb\mongodb.conf
    2016-04-13T01:19:44.113+0800 W -        --diaglog is deprecated and will be removed in a future release
    2016-04-13T01:19:44.114+0800 I COMMANDS diagLogging level=3
    2016-04-13T01:19:44.116+0800 I COMMANDS diagLogging using file C:\mongodb\data/diaglog.570d2e30
    ...
    
  4. Connect to MongoDB
    C:\mongodb\bin>mongo
    MongoDB shell version: 2.7.7
    connecting to: test
    >
    >show databases; // list all local mongo Db
    admin       (empty)
    local       0.078GB
    useracctDB  0.078GB
    >use useracctDB;
    switched to db useracctDB
    >show collections;
    sessions
    system.indexes
    users
    >db.users.find() // if no record it simple return NONE
    >db.users.find() // otherwise
    { "_id" : ObjectId("572a28bb4f06ab8808567d7e"), "job_title" : "webdev", "email" : "user1@m.com", "hashed_password" : "CgQblGLKpKMbrDVn4Lbm/ZEAeH2yq0M9lvbReMq/zpA=", "username" : "user1", "__v" : 0 }
    
    ...
    
  5. How to add mongo.exe to your windows environment path (optional)
  6. 1. Right Click on My Computer
    2. Choose Properties and Advanced System Settings
    3. Click the Environment Variables button
    4. Under system variables scroll down and double click on Path.
    5. Append the following to the existing Variable value.

    ...;C:\wamp\bin\php\php5.3.9;C:\mongodb\bin\
    ...
    
  7. How to add MongoDB as Windows service
  8. C:\>mongodb\bin>mongod --config "c:\mongodb\mongodb.conf" --install --serviceName mongoDB --serviceDisplayName "MongoDB Server Instance 27017" --serviceDescription "MongoDB Server Instance running on 27017"
    ...
    

    Onced the service is added, mongoDB will start automatically after system restart.
    Or you can now manually start it by using the command: net start mongoDB to start, net stop mongoDB to stop

    If you want to remove the service, simply execute:

    C:\mongodb\bin>mongod --remove
    2016-04-13T23:09:57.234+0800 I -   Trying to remove Windows service 'MongoDB'
    2016-04-13T23:09:57.236+0800 I -   Service 'MongoDB' removed
    

    note: Install MongoDB as Windows service on Windows 8, but hit “Access is denied.” error message. To fix it, run the Command Prompt with Administrative Privileges – right click on the command prompt icon, select run as administrator.

Advertisements