MongoDB 3.0 Authentication Issue

We upgraded to MongoDB 3.0 version and that caused some of the tools that we used for visualization of Mongo data to stop working.  We use Robomongo at my workplace and it started failing with Authentication error.  The error I saw was as follows:

Failed to authenticate admin@admin with mechanism MONGODB-CR: AuthenticationFailed MONGODB-CR credentials missing in the user document

There is a JIRA ticket that is open on the Mongo Issue list which can be found here.  As mentioned in the issue, MONGODB_CR was an older authentication algorithm that was used prior to 3.x versions.  This causes third party tools to stop working when we move to Mongo 3.x because they still try to authenticate using the older mechanism instead of using the newer SCRAM-SHA-1.  I had to perform the following steps to fix the issue and it seems to have worked:

  1. Start MongoDB in non authenticated mode. From the command line, it will be the command
  2. mongod
  3. Switch to the admin database, which stores the usernames and passwords for all users that might need authentication.  If you are using some custom database to store the users, switch to that database
  4. use admin
  5. Now we need to change the authentication schema used for authentication to MONGODB_CR. The value assigned for newer schema is “5” and for the older one is “3”
  6. var schema = db.system.version.findOne({"_id" : "authSchema"})
    schema.currentVersion = 3
    db.system.version.save(schema)

Once the above change is applied, I still was not able to use mongo with authentication. I had to drop and recreate existing users for Robomongo to successfully connect to mongo db in authenticated mode. Once the third party tools also upgrade to work with proper authentication, refer to the link here to again upgrade to using the SCRAM-SHA-1.

Advertisements

Motorcycle DL389 in US

I’ve always loved riding a bike.  In India, it provides the advantage of finding easy parking, faster maneuverability and it takes up less space in the garage.  I owned a 100cc Splendor in India and it served it’s purpose but I always envied friends with faster and larger bikes.  I wanted to get a CBZ as my first bike but why I didn’t end up getting one is an entirely different story (Stupid salesman and his thoughts on speeding!!!).

When I came to Texas for grad school, I noticed a large number of people driving on I-20 using cruiser bikes and I always felt that when I grow old, this is something I can see myself doing as well and don’t get my started on my love of sports bikes!!  The zippy machines that zoom past you during the morning traffic on 101 do generate some envious glares from the car drivers.  And then one of my friend ended up getting a bike in Texas and that meant I should at the very least get a head start in pursuing this dream to cruise around at old age.  The first step is to get a driving license from DMV.  Now, there are two ways to do this

  1. Get a learning permit, drive a bike around for few months and finally give your driving test at DMV
  2. Join a Basic Rider Course, attend classroom sessions and at the end of the course, get the DL389 (waiver to give riding test)

For the approach 1, you need to have a motorcycle or know someone who has one to clear the driving test.  I opted for option 2 as the classes arrange for the bike, give you practice and then finally test you on the skills acquired during the course.

Bike Smart – Basic Rider Course

First off, please start looking for a class way in advance… these classes are always full and it was very difficult to get into one for me.  I booked a class for September labor day weekend almost a month in advance.  The classes are divided into classroom sessions and riding sessions.  The class I took had following schedule:
Classroom 6:30 PM to 10 PM on Thursday, Riding session 1:00 PM to 6 PM on Saturday followed by 6:30 pm to 10 PM classroom and finally one more riding session on Sunday from 1:00 to 6 PM.  PLEASE BE ON TIME as they are not kidding about the timing policy and I actually had 2 people sent away just because they were a minute late.

The first classroom session was with Chris (The professor) and he was really fun.  The classroom chairs are such that it starts hurting after sitting continuously for 4+hours but the session was informative and fun and Chris encouraged asking questions and spoke about his bike, his driving experiences and such.  The second classroom was taken by Chris which was kind of slow and I got a seat in a corner and he was seating most of the time so I didn’t have as much fun as the professor’s class.  Both the classroom sessions simply went over a prepared presentation but the information from the instructor’s driving experience was good.

The riding sessions were HOT!!!  Temperatures went up to about 90 degrees and so please bring water, dollar bills for food or carry something with you.  Clifton and Chris (Lean older guy who is super lean and wears cowboy hat) took the riding sessions.  They seemed a little patronizing and I was super nervous reading the reviews beforehand on yelp.  At first, I didn’t understand if the guys were joking with us or seriously scolding someone.  However, they were really helpful in getting rid of our bad habits and Cliff was super helpful once I survived the first day.  I can totally imagine hanging out with these two instructors and learning about bikes.  Just drive as best as you can and hang on to each of their words and you should be good.  They make you practice all the stuff prior to riding test and so you are well prepared.  I deducted one start because I felt that they could have provided more help/insights and were sometimes not paying as much attention even when we were making mistakes.

The riding test was 5 rounds of different tasks.  It was easy if you paid attention but the last test is kinda difficult to understand where they ask you to mimic real life driving situation.  They give you feedback and test results on the very same day so that was cool to know that I passed with the highest score in my class 🙂  I got my DL389 in mail in about 4 days and then you simple need to schedule a written test with DMV and get your M1 license.  Overall, I recommend this class to catch up on your riding skills but it might be slightly difficult for totally new beginners.

The Spy: Movie Review

Spy (2015)

Spy Movie poster

THE CAST

Spy is a movie directed by Paul Feig and stars Melissa McCarthy, Jason Statham, Jude Law, Rose Byrne, Miranda Hart, Allison Janney and Bobby Cannavale in prominent roles.  It also stars Nargis Fakhri in a guest role.

The Story

Melissa McCarthy plays Susan Cooper, a CIA analyst who goes into the field following the disappearance of a suave super-spy portrayed by Jude Law.  Statham played an overconfident yet clumsy spy and Cannavale plays a villain along with .

A suitcase nuke has been stolen by a gangster, who gets accidentally shot by Jude Law.  This means that the only person left who knows the location of the nuke is his daughter.  McCarthy has to leave her desk job and play a super spy like Bond, which causes the funny moments in the movie.

The Good

  • Jason Statham in a surprise comic role is super funny.  His one liners are hilarious and his overconfidence always gets him in trouble
  • Melissa McCarthy shines in her role and provides ample of hilarious shots.
  • Peter Serafinowicz and his role of italian spy that is obsessed with making out with Melissa is also funny.

The Bad

I loved the movie too much to find any faults with it.  It was hilarious and funny and the only bad was too much cursing and lots of british accent.

Conclusion

Very funny and must watch movie not to be missed.  I give it 4 stars out of 5 (a star for Jason coz am a huge fan!!).

Toyota Prius: My new car

The new car!

The Toyota Prius 2015!

I moved to San Jose last year from San Francisco but my workplace is still located in San Bruno.  This means driving about 35 miles one way on US-101 or 44 miles on 280.  I guess taking the train would have been one option but that is a bit inconvenient as the station is 5 miles from my place.  I have to pay for parking and monthly pass which adds up to a large number.  Finally, after driving my Altima Coupe for almost a year on the long traffic filled roads of the bay area, I decided it was time to get a car that is efficient and economical.

I hated the Prius to be honest.  With all the bad name that it has accumulated over the years, I never thought I will end up buying one.  However, when my colleague got a Prius and I noticed that it gave a mileage of 55-60 MPG I could not resist buying one.  I am in my 30s and hence I can afford buying a Prius (In my 20s, I would’ve made fun of someone driving the stupid car!!).  I have driven about 1000 miles in the first week since I bought it and am listing my experience with driving the car below.

PROS

The biggest advantage of driving the Prius is the mileage!!  I love the way it drives on Electric power in peak trafiic and at times when there is slowly moving traffic.  Even when driving at speeds ~60 miles per hour, it manages to deliver close to 40 mpg.  The display is also helpful in monitoring the real time gas usage and it has helped me adjust my driving so as to achieve better mileage.  I kind of have a small competition where each day I try to beat the average mpg for the trip to office n back.

The second good thing about the Prius is that it is a good package.  It offers rearview camera, good stereo with 6 speakers, keyless entry, push button start, drop flat seats, digital odometer, bluetooth connectivity, USB charging and a good enough cabin space for a decent price close to 23K for the base version.  With ongoing promotions on loans (0% APR for 60 months), it was quite a steal.

Lastly, It is a toyota and even though Prius has earned a bad reputation previously, I believe that the maintenance should not be an issue.  The company also offers prepaid maintenance packages which are good for the value they offer.

CONS

The car is really SLOOOOOWWWWW!!  I have compared driving the Prius and my older Altima and the Altima is zippy and makes merging on freeways a breeze.  With Prius, merging onto the freeway or driving on an uphill slope is a battle.  The pickup of the car even with POWER Mode on is slow.  It is a mere 99HP engine so don’t have huge expectations from the car!!

This car makes no sound at all in EV mode.  I have made the mistake of stepping out of the car and forgetting to turn off the engine because it makes 0 noise.

All in all, I am loving the car.  The mileage is awesome and if you adjust your driving skills a bit, the drive ain’t so bad.

Cricket

Finally, after almost 7 years I played cricket over the weekend.  It was fun playing with tennis ball on a small pitch with all sorts of weird rules.  Hitting the ball hard – out, one bounce one hand catch – out, if you hit the ball and it goes behind you – out!!  It was as if we turned into kids and got the Cricket world cup fever.

I was the only lefty on the team and even though I played after a long time, I managed to score some decent runs.  My bowling sucks big time though and hope we continue to play this form of ‘gulli’ cricket atleast every weekend 🙂

Oracle: Export empty tables

When taking a database dump from Oracle 11g recently, I found that the export did not include tables that had 0 rows.  The Oracle11g instance implements a space saving measure where if your table has no data, it will not be exported.  Space is allocated only when you add data to the table.

A workaround to the issue is to pre-allocate some space to such empty tables.  Execute the following oracle queries to allocate space for all tables before taking the export:


select 'alter table '||table_name||' allocate extent;'
from dba_tables
where segment_created = 'NO'
and owner = 'DB_USER;

Running the above query will generate some alter table statements for all tables with empty data.  Executing these SQL statements will allocate space to the empty tables and allow you to export and import such tables.

TCS Layoffs Controversy

Recently, there has been too much hoopla in the news about the exit interviews being conducted at Tata Consultancy Services (TCS).  TCS is one of the largest Indian IT firms and they started to let go employees to cut down on costs.  I feel really bad for the employee that was let go and totally sympathize with her but there is nothing inhumane or wrong with layoffs.

We always imagine that we will have a secure and stable job and everybody makes decisions based on this fact.  We take mortgages, auto loans, decide on a rental place, etc based on the assumption that we will always earn X amount of money.  I can only imagine what the woman would’ve felt when HR told her we are sorry but this is your last day!!  However, this is part of workforce optimization.  Large corporations like Microsoft, Cisco, etc also have to layoff employees that are under-performing or just meeting expectations so that they can retain good talent.  Also, if a company is making losses, it has to think for the greater good.

It would have been totally unfair if the person was laid off without any monetary compensation.  TCS pays 3 months of salary as severance pay which sounds humane enough.  The really stupid thing is when judiciary gets involved and puts a stay order on the termination of employee because she is pregnant!!  So if a guy is let go that would be fair but firing a pregnant lady is not lawful?!

I truly hate layoffs and hope nobody has to face it.  However, I don’t agree with claims that TCS layoffs were not humane.

Mongodb JAVA Driver: QueryBuilder class

I was recently assigned a task where I had to convert a SQL like where clause query into Mongo query on the fly.  There are some good drivers available to do the same but they are not free.  The best example is UnityJDBC but it was a bit expensive for our use case.  The query needed to be super simple and we made the following assumptions:

  1. We need to support simple SQL statements that don’t have brackets.  Hence, type = exam and score >= 60 is acceptable but type = exam and (score >=60 or score < 30) is not acceptable
  2. The query will only work against double for >, <, >=, <= and will support String and Double datatype when querying for = and != operators.

We decided to come up with something in-house that would be sufficient enough to satisfy our needs and we can build on top of the framework over time like adding support for brackets, Logical operators like XOR, etc.  Let’s use the following sample data to proceed with the example:

{ "_id" : { "$oid" : "50906d7fa3c412bb040eb577" }, "student_id" : 0, "type" : "exam", "score" : 54.6535436362647 }
{ "_id" : { "$oid" : "50906d7fa3c412bb040eb578" }, "student_id" : 0, "type" : "quiz", "score" : 31.95004496742112 }
{ "_id" : { "$oid" : "50906d7fa3c412bb040eb579" }, "student_id" : 0, "type" : "homework", "score" : 14.8504576811645 }
{ "_id" : { "$oid" : "50906d7fa3c412bb040eb57a" }, "student_id" : 0, "type" : "homework", "score" : 63.98402553675503 }
{ "_id" : { "$oid" : "50906d7fa3c412bb040eb57b" }, "student_id" : 1, "type" : "exam", "score" : 74.20010837299897 }
{ "_id" : { "$oid" : "50906d7fa3c412bb040eb57c" }, "student_id" : 1, "type" : "quiz", "score" : 96.76851542258362 }
{ "_id" : { "$oid" : "50906d7fa3c412bb040eb57d" }, "student_id" : 1, "type" : "homework", "score" : 21.33260810416115 }
{ "_id" : { "$oid" : "50906d7fa3c412bb040eb57e" }, "student_id" : 1, "type" : "homework", "score" : 44.31667452616328 }
{ "_id" : { "$oid" : "50906d7fa3c412bb040eb57f" }, "student_id" : 2, "type" : "exam", "score" : 19.88180838833524 }
{ "_id" : { "$oid" : "50906d7fa3c412bb040eb580" }, "student_id" : 2, "type" : "quiz", "score" : 1.528220212203968 }
{ "_id" : { "$oid" : "50906d7fa3c412bb040eb581" }, "student_id" : 2, "type" : "homework", "score" : 60.9750047106029 }
{ "_id" : { "$oid" : "50906d7fa3c412bb040eb582" }, "student_id" : 2, "type" : "homework", "score" : 97.75889721343528 }

Let me start by showing a simple program that we can use to get all records for student with student_id of 2.  There are two classes available to allow us to do this.

1. Using BasicDBObject class:


import java.net.UnknownHostException;
import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.Mongo;

public class BasicDBObjExample
{

public static void main(String[] args) throws UnknownHostException
{
// Connect to the Mongo database
Mongo mongoConn = new Mongo("localhost", 27017);
DB mongoDb = mongoConn.getDB("DP_TEST");
DBCollection collection = mongoDb.getCollection("DATA");

// Building the query parameters
BasicDBObject studentFinder = new BasicDBObject();
studentFinder.put("student_id", 2);

// Fetch the records for the query.  collection.find() will return Cursor with records that match the query DBObject
DBCursor dbCursor = collection.find(studentFinder);

while(dbCursor.hasNext())
System.out.println(dbCursor.next());
}

}

2. Using QueryBuilder class:


import java.net.UnknownHostException;
import com.mongodb.QueryBuilder;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.Mongo;

public class QueryBuilderExample
{

public static void main(String[] args) throws UnknownHostException
{
// Connect to the Mongo database
Mongo mongoConn = new Mongo("localhost", 27017);
DB mongoDb = mongoConn.getDB("DP_TEST");
DBCollection collection = mongoDb.getCollection("DATA");

// Building the query parameters
QueryBuilder studentFinder = new QueryBuilder();
studentFinder.put("student_id").is(2);

// Fetching the records for the query. get() method will convert QueryBuilder -&gt; DBObject class of query parameters
DBCursor dbCursor = collection.find(studentFinder.get());

while(dbCursor.hasNext())
System.out.println(dbCursor.next());
}

}

Notice that both the examples return the same set of records.  The only difference is in the way we construct the query to be run against the Mongo database.  The QueryBuilder class comes handy when you have A < 10 and A > 20 kind of queries.  For example, let us find records where student_id > 0 but < 2.  The query construct will be as follows for BasicDBObject :

BasicDBObject studentFinder = new BasicDBObject();
studentFinder.put("student_id", new BasicDBObject("$gt", 0).append("$lt", 2));

The syntax is simpler in case of QueryBuilder as follows :

QueryBuilder studentFinder = new QueryBuilder();
studentFinder.put("student_id").greaterThan(0).and("student_id").lessThan(2);

Finally, based on the above example, we can create queries at run time.  We are using groovy language and Java 1.7 for our framework and so the sample method to convert filter string at run time will be as follows:

	// Process queries of type A > 10 and B < 5 and B > 1
	private static QueryBuilder getQueryBuilderByString(String filter) {
        if(filter == null || filter=="") return null;
        String[] filters = filter.split(" ");
        QueryBuilder q2 = new QueryBuilder();
        for (int i = 0; i < filters.length; i++) {
            if (i == 0) {
                q2.put(filters[0]);
                continue;
            }
            switch (filters[i]) {
                case ">":
                    if (i + 1 <= filters.length)
                        q2.greaterThan(filters[i + 1].toDouble());
                    else
                        return null;
                    i += 1;
                    break;
                case ">=":
                    if (i + 1 <= filters.length)
                        q2.greaterThanEquals(filters[i + 1].toDouble());
                    else
                        return null;
                    i += 1;
                    break;
                case "<":
                    if (i + 1 <= filters.length)
                        q2.lessThan(filters[i + 1].toDouble());
                    else
                        return null;
                    i += 1;
                    break;
                case "<=":
                    if (i + 1 <= filters.length)
                        q2.lessThanEquals(filters[i + 1].toDouble());
                    else
                        return null;
                    i += 1;
                    break;
                case "=":
                case "==":
                    if (i + 1 <= filters.length)
                        if (filters[i + 1].isDouble())
                            q2.is(filters[i + 1].toDouble());
                        else
                            q2.is(filters[i + 1].toString());
                    else
                        return null;
                    i += 1;
                    break;
                case "<>":
                case "!=":
                    if (i + 1 <= filters.length)
                        if (filters[i + 1].isDouble())
                            q2.notEquals(filters[i + 1].toDouble());
                        else
                            q2.notEquals(filters[i + 1].toString());
                    else
                        return null;
                    i += 1;
                    break;
                case "and":
                case "AND":
                    if (i + 1 <= filters.length)
                        q2.and(filters[i + 1]);
                    else
                        return null;
                    i += 1;
                    break;
                default:
                    break;
            }
        }
        return q2;
    }

Refer the QueryBuilder API documentation for more info.

ORA-28001: The password has expired

I am a heavy user of Oracle database and I have installed the Oracle 11g on my desktop at work.  We use it as our primary database and I created several different instances of database users on my local edition of the RDBMS.  Recently, I logged into an old DB user that I had created on my desktop after quite some time.  It was an older version of our software and so when the Services team reported a bug, I wanted to spin up the instance and try to debug the reason for the error.

When I tried logging into the DB, I kept getting the ORA-28001: The password has expired error.  Now, I am familiar with changing password and I fired up a command prompt, logged in as the root.  I ran the query below to change the password:

        SQL> ALTER USER system_36 IDENTIFIED BY system_36; –system_36 is the existing username and password

When I tried logging in as system_36, it again gave me the same error of ORA-28001.  On doing some research I found that by default the password expiry is set to 180 days.  The account doesn’t fix itself simply by changing the password on it.  I am outlining the solution that worked for me below:

1. Connect to the database with sysdba privileges (sys user).
2. Execute the following script to identify the profile for which you want to set the password life to unlimited from the regular 180 days default setting.        SQL> SELECT * FROM dba_profiles;
3. In case you want to apply the behavior to all future users, execute the query below else replace the DEFAULT profile with profile you want to change
SQL> ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;
4. Now to unlock the user account execute the following query
SQL> ALTER USER system_36 ACCOUNT UNLOCK;
5.  Now you can change the password/apply the existing one again using the following query
SQL> ALTER USER system_36 IDENTIFIED BY system_36;

The user information is stored in dba_users table if you want to check and unlock other users on the same server.

Lindt: Intense Orange

For quite some time I was a huge fan of Cadbury’s Dairy Milk – Fruit and Nut flavor, then I ate Lindt Intense Orange.  Awesome is the only thing that I can think of to describe this bar of chocolate.  Lindt’s Intense Orange Excellence Bar is by far the best chocolate I’ve tasted in the USA.  It is a dark chocolate bar consisting of Orange zest, almond slivers and hint of pineapple.  It combines the intense flavor of dark, silky smooth chocolate with the tangy and zesty orange.  It has superb after taste and I am addicted to it!!  In this month alone I ate about 4 bars and I really have to control myself everytime I go grocery shopping to not get more.  It does pack some high calories but its worth each single bite.

Every once a while, people get asked what would be the last meal you would like before you die and for me I don’t know what the meal would be but I know for sure that dessert is gonna include this piece of chocolate 🙂

Highly recommended piece of chocolate and the best out there.