DennyDotNet

Awesome ASP.NET C# and other cool coding stuff

About the author

Denny Ferrassoli
Developer at Casting Networks. MCP / .NET
E-mail me Send mail
Add to Technorati Favorites

Recent posts

Recent comments

Authors

Categories

None


Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010

NoRM MongoDB and Distinct on an array

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!

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Tags:
Posted by Denny on Friday, May 14, 2010 11:11 AM
Permalink | Comments (0) | Post RSSRSS comment feed