Important: Please read the Qt Code of Conduct -

[Announcement] QtMongo: access to MongoDB from QML

  • Hi,

    if anybody is interested: I created a QML plugin to access MongoDB (a NoSQL database).
    Using MongoDB you don't need any SQL commands, the interface to the database is very javascript-orientated.
    If you like, you can try it at
    but please don't expect too much. It's in a very early development status.
    Feedback very welcome!



    QtMongo Demo Code:
    import Qt 4.7

    ListView {
    id: listview
    width: 300
    height: 500

    MongoDB {
        id: db
        name: "testdb"
        host: "localhost"
        collections: [
            MongoCollection {
                    id: mythings
                    name: "things"
    delegate: mydelegate
    // this corresponds to mythings.find({})
    model: MongoQuery {
        collection: mythings
        query: {}
    Component {
        id: mydelegate
        Text { text: obj.toString() }
    Rectangle {
        id: rectangle1
        x: 183
        y: 72
        width: 100
        height: 100
        color: "#d53737"
        MouseArea {
            id: mouse_area1
            anchors.fill: parent
            onClicked: {
                // this corresponds to SQL's "WHERE j=5":
                console.debug( db.collection("testdb.things").find({j:5}) )
                // insert an object:
                console.debug( db.collection("testdb.things").insert({ddd:445}) )
                // find all objects with "j=5" and present it in the listview:
                listview.model = db.collection("testdb.things").find({j:5})
                // find all objects and present it in the listview:
                listview.model = db.collection("testdb.things").find({})
                // find all objects with ddd=445, create a copy of it (upsert) and modify ddd to 446:
                console.debug( db.collection("testdb.things").update({ddd:445},{ddd:446}, {upsert: true}) )
                // find all objects in mythings
                console.debug( mythings.find({}) )
                // map reduce:
                var map = function() { emit(this.j); }
                var reduce = function(k,vals) { return 1; }
                // take care: you've got to call toString() for each function!
                console.debug( mythings.mapReduce(map.toString(), reduce.toString()) )
                // but you cannot get the result of mapReduce, yet. That's what I'm currently working on


  • Great idea, I will follow this development.

  • That's great stuff and I will test it.

  • I like MongoDB and nice to see QML binding. What is the target platform? I wonder if MongoDB itself builds on Symbian, for instance.

  • Me too, to idea of your project for me is to work with small database structures with the advantage of the database without the weight ot sql. What I have not yet clear, is what can be the advantage regardless of my considerations to work with a non-standard database.

  • It's me again!

    I just finished some work: I've removed a lot of C++ code and just copy-paste'd the MongoDB shell scripts.
    That superseded a lot of development. Almost all the code in written in Javascript and it's (probably) feature complete (but probably not free of bugs).
    If you like, just try it and tell me if there are any bugs.

    bq. What is the target platform?

    Currently, it uses the standard MongoDB-C++ driver. I'm working under Linux and I've never used Symbian. So you better ask a Symbian developer if this would work.

    bq. What I have not yet clear, is what can be the advantage regardless of my considerations to work with a non-standard database.

    Sorry, perhaps I have a language problem here: I don't understand what you mean.

  • Hello!

    Sure, I try asap. At the moment I should finish a couple of app, but before the end of the week, I download the repo and start to check all. The main use I need to do with this database is on symbian platforms, so if you can be patient for a couple of week I update you on the results. I give you more news on the application (developing) I choice to test Mongo-DB.

    Many thanks for sharing this useful work.

  • Ok, just a status update:
    I'm currently working to make MongoDB's JS test units pass.
    The problem is, that MongoDB's shell uses custom types (like NumberLong, BinData...) and it's quite difficult to make these work in QML, but I think I have a plan now, how to do it...

  • I gave up on MongoDB a year ago because its drivers can be crazy hard to compile (at least on Windows). I got the C++ driver to build, finally, after a number of hours, using a MSVC compiler. I love the idea of Qt integration (and bugged several employees of the company who makes Mongo about it, at the meetings they host about general C++ development), so I have high hopes for this project, but am still stumbling on build problems. In particular, Qt plays much nicer with MinGW but Mongo buddies up better with MSVC, so trying to build QtMongo I've been unable to resolve problems with wsiapi (the windows socket implementation). Any suggestions? Thanks

Log in to reply