Category Archives: mongodb

MongoDB: Get a random record

Get a random record in Mongo

A quick and simple function that picks a random record from a cursor:

Example:

[DEPRECATED] CentOS 6: Install MongoDB Java REST server

Verisons

  • CentOS 6.4
  • Oracle Java 1.6 JDK
  • MongoDB 2.4

Prerequisites

Install

1. Download, extract tar and mv to /usr/lib

Install as a service

1. Edit /etc/init.d/mongoser

Note: the script hard codes JAVA_HOME, but this could be deferred to the /etc/sysconfig/mongoser script (which you must create) if desired. Note that the normal /etc/profile.sh is *not* run for services.
2. Make it executable

3. Start service

4. Start service on boot

Test

1. Get a list of databases

Output:

Source

CentOS 6: Install MongoDB

Versions

  1. CentOS 6.5
  2. MongoDB 2.4.10

Install

  1. Edit /etc/yum.repos.d/10gen.repo

  2. Install

Configure

  1. Start service

  2. Start on boot

Test

Optional: Open firewall port

  1. Open port 27017 for mongodb See CentOS 6: Open a port for iptables