NoSQL – mongodb vs eXist

There are similarities between mongo and eXist in that they are both document orientated and work with collections of documents.
The main difference is that eXist uses XML documents and mongo uses JSON documents.

There’s plenty of documentation on both but from my point of view it’s quite interesting to compare them and will help my understanding!

(At this point I’m just starting out with mongo and have done more with eXist – see this project which is java war containing a REST based service that uses eXist as it’s back end)

eXist uses xquery as it’s query language
With eXist as you are running in an application server you can write a .xql which directly returns your data, or even HTML, and it’s even possible to wrap with java etc e.g. if you want to implement Spring Security or you can just use it as a database server (albeit one running in a java app server)
eXist also has a REST interface, XML-RPC, the java XML:DB api etc see here for more details.

Mongo acts more like a tradition database server with a command shell and to act as a web server requires an additional interface e.g. using python – an example of a REST service is here

There’s a nice comparison between mongodb and sql here
In mongo you can show the collections using the command show collections

To list a collection you use db.collection name.find() this being like SELECT * FROM table or collection('collection name') or xmldb:xcollection('collection name') in xquery

So for a collection ‘test’ containing atom entries in eXist you might do something like this (xquery):

 let $all-recs := xmldb:xcollection( 'test_collection' )/atom:entry (: not recursive :)
 let $test-recs := $all-recs[atom:title[. = 'Test']
 let $author := for $rec in $test-recs
                   let $auth = $rec/atom:author
                   return $auth

or in mongo

 db.test_collection.find({"title": "Test"})

so in eXist you are using XPath whereas in mongo you are writing a json document that matches the document you want to retrieve.

What’s the conclusion?

MongoDB is sexy at the moment and there’s a lot more information available and it looks quite easy to use.

eXist (and it’s big brother MarkLogic) is more niche but the XQuery/XPath language is probably more powerful than the direct mongo syntax. XForms, e.g. Orbeon, also provides a pretty simple way to edit the XML once you’ve got your head around it.

Most languages have pretty good support for either JSON or XML processing.

Overall I think it’s a case of horses for courses but there’s a strong argument for sticking with traditional SQL databases all of which can handle XML text fields with XPath queries and some can handle JSON – it’s even quite easy to serialize XML to a database using HyperJAXB3 which uses JAXB and JPA – see this project. These days it’s also really easy to knock up a simple CRUD application using something like grails.

I can certainly see a case for eXist where you are working with relatively unstructured XML documents – journal articles would be a good example here – XForms is a nice tie in too.

MongoDB is a good candidate if you are using JSON data – for example in an application which is heavily Ajax/REST based and would cope well with a lot of sparsely populated data – could be pretty good for prototyping where you want to change your data structures a lot e.g. with angular js and a python service and of course it’s "web scale" for when your app takes over the world!
(A humourous mongodb mysql comparison here which gets a bit out of control half way through)

Rookie python

When running in a virtualenv don’t forget to source bin/activate

Install packages using pip e.g. pip install beautifulsoup4

Create a REQUIREMENTS file using pip freeze and load using pip install -r REQUIREMENTS

Creating a module you need in the directory in order to import successfully otherwise you’ll get AttributeError: 'module' object has no attribute 'xxxx'

Javascript debugging using Eclipse

Start Chrome with remote debugging enabled

google-chrome --remote-debugging-port=9222 --user-data-dir=/home/iwright/chrome

Create a new debug configuration using WebKit Protocol

Host localhost
Port 9222
Wip backend Protocol 1.0

Software update site

grails – the very basics

A lightening fast summary of how to create a CRUD application using grails.
In many ways this is a similar to using Spring Roo (see this post) but with Grails/Groovy instead of Spring Roo.
There are a lot of similarities between the two approaches and, of course, if you want to you can mix java and groovy…

This is a very brief precis of this developer works series

Set up some classes with simple list, edit, delete

From the grails command prompt (Ctrl-Alt-Shift G in STS)

create-domain-class Trip


Add some fields (no need for ; )

String name
	String city
	Date startDate
	Date endDate
	String purpose
	String notes



generate-all package.Trip


Change content of TripController.groovy to


def scaffold = Trip

Remove views (if you don’t want to customize them later) – you can always recreate them with

generate-views Airport

Do the same for Airline

Define many to one relationships

static hasMany = [trip:Trip]

If you want cascading deletes the add a belongsTo (otherwise just declare)

static belongsTo = [Airline]

Set some constraints

	static mapping = {
		table 'some_other_table_name'
		columns {
		  name column:'airline_name'
		  url column:'link'
		  frequentFlyer column:'ff_id'

	static constraints = {
		name(blank:false, maxSize:100)
	static hasMany = [trip:Trip]
	String name
	String url
	String frequentFlyer
	String notes

	String toString(){
		return name

DB config

install-dependency mysql:mysql-connector-java:5.1.20

In grails-app/conf/BuildConfig.groovy uncomment the mysql dependency

In grails-app/conf/DataSource.groovy

 driverClassName = "com.mysql.jdbc.Driver"
  username = "grails"
  password = "server"
  url = "jdbc:mysql://localhost:3306/trip?autoreconnect=true"

Create a custom taglib

create-tag-lib Date
class DateTagLib {
  def thisYear = {
    out << Calendar.getInstance().get(Calendar.YEAR)
<div id="copyright">
&copy; 2002 - <g:thisYear />, FakeCo Inc. All Rights Reserved.
class DateTagLibTests extends GroovyTestCase {
  def dateTagLib

  void setUp(){
    dateTagLib = new DateTagLib()

  void testThisYear() {
    String expected = Calendar.getInstance().get(Calendar.YEAR)
    assertEquals("the years don't match", expected, dateTagLib.thisYear())


Similar to .jspf – use an _ e.g. _footer.gsp

<g:render template="/footer" />


To use your own templates instead of the defaults e.g. for default scaffold