MongoDB

 
 
MongoDB is an open source document-oriented database system. It is part of the NoSQL family of database systems. Instead of storing data in rows and columns as one would with a relational database, MongoDB stores a binary form of JSON documents (BSON), making the integration of data in certain types of applications easier and faster.

The latest MongoDB version can be downloaded from: http://www.mongodb.org/

rss feed

Quick guides






Installing MongoDB 2.4.4 on Windows



Information
none

Operating system used
Windows Vista Home Premium SP 2

Software prerequisites
None


Procedure
  1. Download the binary MongoDB for Windows 32-bit distribution v2.4.4 and unpack it.
    For example: c:\tools\mongodb-win32-i386-2.4.4

  2. MongoDB requires a data folder to store its files. The default location for the MongoDB data directory is C:\data\db. Create this folder using the command prompt.

    Type: cd c:\
    Type: mkdir data
    Type: mkdir data\db

  3. To start MongoDB, goto c:\tools\mongodb-win32-i386-2.4.4\bin\
    Type: mongod

    You should see the following:

    c:\tools\mongodb-win32-i386-2.4.4\bin\mongod.exe --help for help and startup options
    Thu Jun 27 13:19:50.283
    Thu Jun 27 13:19:50.284 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.
    Thu Jun 27 13:19:50.284
    Thu Jun 27 13:19:50.296 [initandlisten] MongoDB starting : pid=5344 port=27017 dbpath=\data\db\ 32-bit host=inspiron
    Thu Jun 27 13:19:50.296 [initandlisten]
    Thu Jun 27 13:19:50.296 [initandlisten] ** NOTE: This is a 32 bit MongoDB binary.
    Thu Jun 27 13:19:50.297 [initandlisten] ** 32 bit builds are limited to less than 2GB of data (or less with --journal).
    Thu Jun 27 13:19:50.297 [initandlisten] ** Note that journaling defaults to off for 32 bit and is currently off.
    Thu Jun 27 13:19:50.297 [initandlisten] ** See http://dochub.mongodb.org/core/32bit
    Thu Jun 27 13:19:50.297 [initandlisten]
    Thu Jun 27 13:19:50.297 [initandlisten] db version v2.4.4
    Thu Jun 27 13:19:50.297 [initandlisten] git version: 4ec1fb96702c9d4c57b1e06dd34eb73a16e407d2
    Thu Jun 27 13:19:50.297 [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=0, build=6002, platform=2, service_pack='Service Pack 2') BOOST_LIB_VERSION=1_49
    Thu Jun 27 13:19:50.297 [initandlisten] allocator: system
    Thu Jun 27 13:19:50.297 [initandlisten] options: {}
    Thu Jun 27 13:19:50.302 [FileAllocator] allocating new datafile \data\db\local.ns, filling with zeroes...
    Thu Jun 27 13:19:50.302 [FileAllocator] creating directory \data\db\_tmp
    Thu Jun 27 13:19:50.371 [FileAllocator] done allocating datafile \data\db\local.ns, size: 16MB, took 0.067 secs
    Thu Jun 27 13:19:50.371 [FileAllocator] allocating new datafile \data\db\local.0, filling with zeroes...
    Thu Jun 27 13:19:50.440 [FileAllocator] done allocating datafile \data\db\local.0, size: 16MB, took 0.067 secs
    Thu Jun 27 13:19:50.441 [initandlisten] command local.$cmd command: { create: "startup_log", size: 10485760, capped: true } ntoreturn:1 keyUpdates:0 reslen:37138ms
    Thu Jun 27 13:19:50.442 [initandlisten] waiting for connections on port 27017
    Thu Jun 27 13:19:50.443 [websvr] admin web console waiting for connections on port 28017


    The "waiting for connections" message in the console output indicates that the mongod.exe process is running successfully.

  4. To connect to MongoDB, goto c:\tools\mongodb-win32-i386-2.4.4\bin\
    Type: mongo

    You should see the following:

    MongoDB shell version: 2.4.4
    connecting to: test
    Welcome to the MongoDB shell.
    For interactive help, type "help".
    For more comprehensive documentation, see http://docs.mongodb.org/
    Questions? Try the support group http://groups.google.com/group/mongodb-user
    Server has startup warnings:
    Thu Jun 27 14:04:36.347 [initandlisten]
    Thu Jun 27 14:04:36.347 [initandlisten] ** NOTE: This is a 32 bit MongoDB binary.
    Thu Jun 27 14:04:36.347 [initandlisten] ** 32 bit builds are limited to less than 2GB of data (or less with --journal).
    Thu Jun 27 14:04:36.347 [initandlisten] ** Note that journaling defaults to off for 32 bit and is currently off.
    Thu Jun 27 14:04:36.347 [initandlisten] ** See http://dochub.mongodb.org/core/32bit
    Thu Jun 27 14:04:36.347 [initandlisten]
    >




  5. MondoDB shell is now connected to mongod.exe running on the localhost interface and port 27017 by default. At the mongo prompt, issue the following two commands to insert a record in the test collection of the default test database and then retrieve that record:

    db.test.save( { a: 1 } )
    db.test.find()


  6. More information about MongoDB shell, type: help

    You should see the following:

    db.help()                  help on db methods
    db.mycoll.help()           help on collection methods
    sh.help()                  sharding helpers
    rs.help()                  replica set helpers
    help admin                 administrative help
    help connect               connecting to a db help
    help keys                  key shortcuts
    help misc                  misc things to know
    help mr                    mapreduce

    show dbs                   show database names
    show collections           show collections in current database
    show users                 show users in current database
    show profile               show most recent system.profile entries with time >= 1ms
    show logs                  show the accessible logger names
    show log [name]            prints out the last segment of log in memory, 'global' is default
    use <db_name>              set current database
    db.foo.find()              list objects in collection foo
    db.foo.find( { a : 1 } )   list objects in foo where a == 1
    it                         result of the last line evaluated; use to further
                               iterate
    DBQuery.shellBatchSize = x set default number of items to display on shell
    exit                       quit the mongo shell


  7. To exit MongoDB shell, type: exit