(+N) Consulting Inc.

Consulting | Software Solutions | Training

Who would save() me now? MongoDB 2.0 C#Driver deprecates save()

For years now, I've been using mongo's save() function on a collection. It's convenient: hand it an document with an id, slam it in and done. With the C# 2.0 driver, (and other drivers as well) it's now gone! Will we miss it? Should we miss it? Lets take a closer look: First – what is the syntactic meaning of "save"? The save function provided add-or-replace semantics . If an document by that id existed, it would be overwritten with the new document . If an document with that id did not exist, then the document at hand would become a new document. Seems legit, right? Consider though, what would happen when a document already existed. It would be gone. Gone in the sense that the new document would overwrite the existing one. I know, I know. W... [More]

Of transactions and Mongo

What's the first thing you hear about NoSQL databases? That they lose your data? That there's no transactions? No joins? No hope for "real" applications? Well, you *should* be wondering whether a certain of database is the right one for your job. But if you do so, you should be wondering that about "traditional" databases as well! In the spirit of exploration let's take a look at a common challenge: You are a bank. You have customers with accounts. Customer A wants to pay B. You want to allow that only if A can cover the amount being transferred. Let's looks at the problem without any context of any database engine in mind. What would you do? How would you ensure that the amount transfer is done "properl... [More]

MVC Model State Validation–DRY to the rescue!

ASP.NET MVC comes with nice features to aid model validation. Unfortunately, you are still stuck writing boilerplate code on all the data entry actions. The boilerplate code looks something like: public ActionResult DoSomething(Foo value){ if (ModelState.IsValid) { return View(); } ...// do actual work return View("AllGoodThanks");}   The common desired behavior is that when the submitted model is invalid the view is immediately returned so the user can fix erroneous entries. But since the flow is such that a value needs to be returned, you can't just refactor this into a common method. What to do? Lets implement DRY (don't repeat yourself. Duh! just did..) based on ActionFilterAttribute... [More]

Manufacturing a MongoDB ObjectId for the past

MongoDB's ObjectId() has some nice sequential properties. One of the interesting ones is the fact that the most significant 4 bytes are a timestamp with seconds granularity. Suppose you want to query your collection for items created on or after a certain date. Since the timestamp portion can be constructed (milliseconds since epoch), and the rest can be manufactured (zero would be fine) we can now write a function to generate what the ObjectId would be or be just higher or lower than:   var past = new Date((new Date()).getTime() - (90 * 24 * 60 * 60 * 1000));var stamp = ObjectId(Math.floor(past.getTime() / 1000).toString(16) + "0000000000000000"); The stamp object contains an ObjectId with a value represent... [More]

MongoDB log rotation

MongoDB's engine can log quite a bit of useful detail. Whether high-transaction rate or verbose, the log can get quite large. While setting the log mode to append helps you retain the old / existing log, mongo does not currently have a facility to rotate the log at prescribed times or when a size limit is reached. In other words, the log will grow indefinitely. There are 2 ways to have the engine release current file and start a new one: SIGHUP Issue a command to mongod via a client connection The first option, available on Unix variants, is issued like so: killall -SIGUSR1 mongod This would force log rotation on all instances of mongod on that machine. The second option requires a connection to mongo. The mongo shell is c... [More]

Custom domain for Windows Azure in the new portal

The new Windows Azure Portal looks great, but has moved things around a bit. This post serves as note to self and others: How do I set a custom domain name for blob/ table/ queue? Go to the new portal https://manage.windowsazure.com/ Click the "Storage" item on the left (icon reminiscent of a table or spreadsheet) Click on the one of your storage items for which you want to create a custom domain Click the "configure" tab (you are in "dashboard" by default) Click the "manage domain" icon on the bottom action bar (look all the way at the bottom between "manage keys" and "delete") Enter the full domain name you want to have point to the storage "bob.mydom... [More]