A little gotcha for anyone using NoRM MongoDB provider and running Distinct on an array.
MongoDB versions earlier than 1.5.0 will return distinct arrays as values. Any version of MongoDB 1.5.0 and above will return distinct values of the arrays. Let me demonstrate:
Object Person:
1. Name: "Joe", Friends: ["Tom", "Chuck"]
2. Name: "Tom", Friends: ["Joe", "Chuck"]
3. Name: "Bill", Friends: ["Tom", "Chuck"]
Now our NoRM code:
MongoCollection<Person> _collection = ...;
// MongoDB < 1.5.0
var results = _collection.Distinct<string>("Friends");
// above code throws an exception
var results = _collection.Distinct<string[]>("Friends");
// results = [ ["Tom", "Chuck"], ["Joe", "Chuck"] ]
// MongoDB >= 1.5.0
var results = _collection.Distinct<string>("Friends");
// results = ["Tom", "Chuck", "Joe"]
So keep an eye out when upgrading MongoDB!