MongoDB: How to make all fields of a collection lowercase

This simple script has been tested on MongoDB 3.2. It should work on older versions of MongoDB as well.

db.collectionName.find( {}, { 'fieldName': 1 } ).forEach(function(doc) {
   { _id: doc._id},
   { $set : { 'fieldName' : doc.fieldName.toLowerCase() } },
   { multi: true }

To convert all fields inside of an array, use this trick… MongoDB: How to lower case all items of an array

MongoDB current operations and profiling

Current operations


Write operations waiting for a lock

    "waitingForLock" : true,
    $or: [
      { "op" : { "$in" : [ "insert", "update", "remove" ] } },
      { "query.findandmodify": { $exists: true } }

Operations that have never yielded

     "active" : true,
     "numYields" : 0,
     "waitingForLock" : false

Index creation operations

      $or: [
        { op: "query", "query.createIndexes": { $exists: true } },
        { op: "insert", ns: /\.system\.indexes\b/ }

Profiling Levels

  • 0 – the profiler is off, does not collect any data.
  • 1 – collects profiling data for slow operations only.
  • 2 – collects profiling data for all database operations.

Checking profiling level


Turn on profiling for operations taking more than 1 second (1000 milliseconds)


Turn profiling off


5 most recent operations logged in the system.profile table

db.system.profile.find().limit(5).sort( { ts : -1 } ).pretty()

Recent operations that took longer than 2 seconds

db.system.profile.find( { millis : { $gt : 5 } } ).pretty()


To change the size of the system.profile collection, you must:

  1. Disable profiling.
  2. Drop the system.profile collection.
  3. Create a new system.profile collection.
  4. Re-enable profiling.

To create a new system.profile collections that’s 4000000 bytes, use the following sequence of operations

db.createCollection( "system.profile", { capped: true, size:4000000 } )


Running MongoDB 2 and 3 on the same computer

Manually install (untar) MongoDB 2 and 3 into two different folders, for example


Create log and data folders for each version


Create a conf file for each version.


Contents of these files can be something like



As you can see here, MongoDB 2 will be running on port 27017 and MongoDB 3 will be running on port 37017

No start each server with the following commands

.../mongodb2/bin/mongod  --config .../mongodb2/mongod.conf
.../mongodb3/bin/mongod  --config .../mongodb3/mongod.conf

That’s it🙂

Two different command line clients can be run as follows

.../mongodb2/bin/mongo --port 27017
.../mongodb3/bin/mongo --port 37017

Datasets For Sentiment Analysis

Movie Review Data

Large Movie Review Dataset

  • This is a dataset for binary sentiment classification containing substantially more data than previous benchmark datasets. We provide a set of 25,000 highly polar movie reviews for training, and 25,000 for testing. There is additional unlabeled data for use as well. Raw text and already processed bag of words formats are provided.
  • Download from:

Multi-Domain Sentiment Dataset

  • The Multi-Domain Sentiment Dataset contains product reviews taken from from many product types (domains). Some domains (books and dvds) have hundreds of thousands of reviews. Others (musical instruments) have only a few hundred. Reviews contain star ratings (1 to 5 stars) that can be converted into binary labels if needed.
  • Download from: