Making backups and importing data – Mongo and xDB part three

There are a few ways you can make a backup with Mongo. The most simple is to take a copy of the database files and put them somewhere safe. This is made easier if you’ve put each database into its own directory. However, this is a pretty naive method as you will have to stop the server and restart it. You also will be taking a full backup. That said, this method does have its uses in a scenario where you are messing around with a secondary but that’s beyond the scope of this short post.

Its possible to extend this a little by using mongodump against the file system. The tool will lock the files so the database cannot be in use at the time but it at least provides a binary export of the data.

For a developer scenario, its more likely that we’ll be using mongodump, mongorestore, mongoimport and mongoexport against our running database. We may need some data from a co-worker or from the live system or we may be the provider of some data to another member of our team.

Continue reading

Securing and navigating around xDB – Mongo and xDB part two

Peeking around

There are a number of options for navigating your way around Mongo. Depending on what you’re most comfortable with, you may prefer using command line tools and batch files or you may prefer GUI tools like RoboMongo, MongoChef or MongoVue. That said, for the more complex operations you’ll have to be comfortable with the command line tools unless you’re hosting with a third party.

The Mongo eco-system is based on a Javascript ‘shell’. This means that all functions, loops and the like follow the normal Javascript syntax rules. It also means that reading any custom functions and profile scripts should be easy for anyone who is familiar with Javascript for web development. Before we continue and look at some simple operations, its useful to repeat some Mongo definitions. Naturally these are all available on the Mongo documentation website so I’ll be brief:

  • Database – the same concept as in a relational product like Sql Server.
  • Collection – similar to a table but doesn’t have a schema
  • Document – a record in a collection.
  • Index – the same concept as in a relational product

When we want to insert data into Mongo, we create a new document and add it to a collection. Mongo also allows us to embed one document inside another which can be useful but does require some care when constructing queries and designing indexes. Once we have some documents, we can pull them out using queries (as you’d expect). These queries can have a bit of a ‘linq’ feel to them due to the use of the Javascript shell. Here’s an example:

use myusertable
db.users.find({"Country": "New Zealand"}).sort( { "Surname": 1, "Firstname": 1 } )

Continue reading

Using MongoDb to provide items as a Cache for Sitecore.

Ok, so I finally managed to get my MongoDB hat back on recently and first thing that struck me is that I forgot how much I love it as a product, the driver is easy to get to grips with, its a doddle to set up and hyper fast :D.

Below I have listed a starting point that I have been working on to serve the latest version of content from Mongo, in part this is to help out in the content editor (and in particular, that item.GetChildren() causes the default item provider to return the latest version from the database, but I expect to extend this to be able to serve all of the web content from such a provider.

This post at present is the basis of a working idea that I have been playing with, but I think with refinement (and certainly until Sitecore provide us a full blown MongoDB based version) it might have mileage to enable us to squeeze a little more performance out of our existing implementations.
Continue reading