Working with MongoDB’s $lookup Aggregator

mongodbartI’ve posted an article “Working with MongoDB’s $lookup Aggregator” on Code Project, here.  This article expands on my previous post and does a deep dive looking at how to use the $lookup aggregator for:

  • one-to-one
  • one-to-many
  • many-to-many
  • nested

joins.

Posted in mongodb, Software Development | Tagged , , , , , | Leave a comment

RoboMongo – Support this project!

robomogoart

After trying out a couple GUI’s for MongoDB, I came across RoboMongo.  It’s easy to use, and it works, as contrasted with MongoVue, which crashed with a NullReferenceException when I tried to create a collection.

The developer is trying to raise enough money to pay for a full time engineer, and so far I’m really impressed with the work that’s been put into this open source project.  So, go fund it.  They got $100 from me.

As Michael Kennedy wrote (in 2013!!!):

Robomongo is definitely my current favorite management tool for MongoDB. It beautifully blends the power of the mongo shell and JavaScript API with a classy and intuitive user interface. Basically every rich UI can be driven by shell commands and then further manipulated with the UI. Brilliant. The fact that it’s free and works on all platforms is nice too.

Posted in Uncategorized | Leave a comment

MongoDB Grows Up – the $lookup aggregator

mongodbartSo far, I’ve been avoiding anything having to do with NoSQL because of the inability to do, in the classical RDBMS world, table joins.  The idea of having to pull into memory (well, my application’s memory) all the results of one table and then join them (with more code) to another table was appalling to me, particularly since I want my queries to be runtime generated by metadata schema.

However, as of the release of MongoDB 3.2, that has changed!  I can now do multiple table (collection) joins, which in my opinion, is critical for working with semantic data.  As Semag points out:

“Data is organized based on binary models of objects, usually in groups of three parts: two objects and their relationship.”

So now, in MongoDB, I can do something very simple (and very non-semantic in this example):

db.createCollection("Person")
db.createCollection("Phone")
db.createCollection("PersonPhone")

db.Person.insert({ID: 1, LastName: "Clifton", FirstName: "Marc"})
db.Person.insert({ID: 2, LastName: "Wagers", FirstName: "Kelli"})

db.Phone.insert({ID: 1, Number: "518-555-1212"})
db.Phone.insert({ID: 2, Number: "518-123-4567"})

db.PersonPhone.insert({ID: 1, PersonID: 1, PhoneID: 1})
db.PersonPhone.insert({ID: 2, PersonID: 2, PhoneID: 1})
db.PersonPhone.insert({ID: 3, PersonID: 2, PhoneID: 2})

Notice I have to tables, Person and Phone (please ignore my case style, I come from a different world, some may say planet).  I can now query the data using the $lookup aggregate function (plus a few other pieces):

db.PersonPhone.aggregate([
{ $lookup: { from: "Person", localField: "PersonID", foreignField: "ID", as: "PersonName" } }, 
{ $lookup: { from: "Phone", localField: "PhoneID", foreignField: "ID", as: "PersonPhone" } }, 
{ $match: {PersonID: 2} }, 
{$project: {"PersonName.LastName":1, "PersonName.FirstName":1, "PersonPhone.Number": 1, _id:0}} ])

and I get a lovely resulting dataset:

{
  "PersonName": [
    {
      "LastName": "Wagers",
      "FirstName": "Kelli"
    }
  ],
  "PersonPhone": [
    {
      "Number": "518-555-1212"
    }
  ]
}{
  "PersonName": [
    {
      "LastName": "Wagers",
      "FirstName": "Kelli"
    }
  ],
  "PersonPhone": [
    {
      "Number": "518-123-4567"
    }
  ]
}

So now I can use finally MongoDB to satisfy the foundational tenet of a semantic database: a relationship between two objects.

And the nice thing about using a NoSQL database is that schema is not fixed in concrete, as it is with a SQL database, which would normally require additional layers of manipulation to deal with the second foundational tenet of a semantic database: that your concept of, say, a person’s name might be semantically different (but still compatible) with mine — especially when we consider culture.

Posted in mongodb, semantic programming | Tagged , , , | Leave a comment

Clarke’s Third Law – Challenge, or Fate?

borg

Arthur C. Clarke’s third law is:

Any sufficiently advanced technology is indistinguishable from magic.

Last Thursday I attended a lecture entitled “Our Children, Our Technology, Our Future”, which was an excellent talk given by Dr. Stephen Sagarin (read his blog “What is Education?” here), discussing the questions:

  1. Given what we know about the development of children, how can we imagine a healthful future with technology?
  2. What characterizes technology as a human creation, and what ethical and educational demands does it require?

It occurred to me that as technology, and the computing devices that operate the technology, becomes more and more advanced, a corallary to Clarke’s third law would be:

Any sufficiently advanced technology is indistinguishable from a human being.

That is, after all, where technology is heading, and has been since Alan Turin, in 1950, developed the Turing Test – a machine’s ability to exhibit behavior indistinguishable from that of a human.

In fact, our machines are being designed to be “better than human”.  Or rephrased, our machines “are beings” designed to be “better than human.”

Rather than accepting this fate, of not just indistinguishable but actually better, the challenge that we, as human beings need to take up, is:

How do we continue to advance ourselves so that human beings continue to be distinguishable from the machine?

And not just by our predilection to violence!

Posted in Uncategorized | Tagged , , , , , | 1 Comment

The Three Criminal Aspects of OOP

police

As a software developer, you’ve undoubtedly been asked by a recruiter, who’s following some script: “what are the three major aspects of Object Oriented Programming?”

And you probably answered something like this:

  • Polymorphism, basically something taking more than one form as you need it. For instance method overloading in C++.
  • Inheritance, in C++ the ability to gain functionality of a parent class in a new child class without having to write that functionality yourself.
  • Encapsulation, the idea behind creating self-contained reusable code that’s hopefully loosely coupled with single points of reference to allow you swap in and out objects as needed or use someone else’s work without knowing the inner workings of an object.

Next time you’re asked a basic question that a) everyone knows, b) anyone can google, answer it this way:

  • Infraction — You’re foot has two operations: push hard, and push harder, on the gas.
  • Misdemeanor — Your child looks like you, their parent, and uses your ID card to buy beer.
  • Felony — The key that unlocks your 1960 VW also unlocks the neighbor’s Porsche.

See what the recruiter thinks of those answers!

Posted in Uncategorized | Leave a comment

Invalid Index Exception trying to load Counter Name

perfctr

 

 

This happened to me yesterday, and of course, Stack Overflow to the rescue.  But it’s such a rare occurrence that I thought I would blog about it.  Here’s the SO link

The offending line of code, which was working perfectly for months until yesterday:

cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total", true);

And I hope that “tdc” doesn’t mind me reposting his answer here:

Although this has already been answered, I see people are repeatedly getting the same error that I did when trying to solve it. If when you run:

C:\windows\system32> lodctr /r

you get the error

Error: Unable to rebuild performance counter setting from system backup store, error code is 2

then you instead need to run

C:\windows\SysWOW64> lodctr /r

after which you should get

Info: Successfully rebuilt performance counter setting from system backup store

 

Posted in Uncategorized | Leave a comment

Can I Sue Pearson for their bogus “Workplace Personality Inventory” results?

gavel
Yesterday I took a “Workplace Personality Inventory” test, apparently put together by Pearson (no, I didn’t pay for it).  I was rather shocked by the results:

  • I am “unlikely to set challenging work goals, and may exert a low level of effort toward achievement of goals”
  • I “may not persist when faced with difficulties or obstacles, or when success seems unlikely”
  • I “have little interest in volunteering for or taking on new work responsibilities or challenges”
  • I “Appear to have little or no interest in taking charge, or directing and leading others; may be hesitant to offer opinions”

So, being a Microsoft MVP for 5 years, a Code Project MVP for, what 13 now, having written (voluntarily, on my own time) over 180 articles, being a consultant for every 20 years, run multiple open source projects, having solved problems that PhD people were unable to solve, etc, etc, etc, and it analyzes my answers into “I’m a lazy, unmotivated, uninterested in challenges, and have no interest in leadership?”

Has anyone else encountered this bullshit?  If so, tell me your story.  I seriously want to sue these people.

Posted in Uncategorized | Leave a comment