Hi there,

I'm developing a QML plugin to make access to MongoDB (a nosql database) possible.

If you like, take a look at my github repository and tell me if you find are any bugs.

Cheers,

Manuel

there also is a demo file:
Qt Code:
  1. // TAKE CARE OF PATH IN qmldir FILE!
  2. import Qt 4.7
  3. import "QtMongo"
  4. import "QtMongo/lib/json/json2.js" as Json
  5.  
  6. Row {
  7. Column {
  8. Text {
  9. text: "<b>Object List:</b>"
  10. }
  11.  
  12. ListView {
  13. id: listview
  14. focus: true
  15. highlight: Rectangle { color: "lightsteelblue"; radius: 5 }
  16. width: 250
  17. height: 500
  18.  
  19. MongoDB {
  20. id: db
  21. name: "testdb"
  22. host: "localhost"
  23.  
  24. collections: [
  25. MongoCollection {
  26. id: mythings
  27. name: "things"
  28. }
  29. ]
  30. }
  31.  
  32. delegate: mydelegate
  33.  
  34. // this corresponds to
  35. // model = mythings.find({}):
  36. model: MongoQuery {
  37. collection: mythings
  38. query: {}
  39. sort: {}
  40. }
  41.  
  42. Component {
  43. id: mydelegate
  44.  
  45. Text {
  46. text: "Object "+_id
  47. }
  48. }
  49.  
  50. onCurrentIndexChanged: jsonEdit.object = listview.model.get(listview.currentIndex)
  51. }
  52. }
  53.  
  54. Column {
  55. width: 500
  56. Row {
  57. spacing: 2
  58.  
  59. Button {
  60. text: "save this object"
  61. onButtonClicked: { mythings.save(jsonEdit.object) }
  62. }
  63. Button {
  64. text: "query this object"
  65. onButtonClicked: {
  66. listview.model = mythings.find(jsonEdit.object)
  67. .toModel(listview.model) // we need a parent here!
  68. }
  69. }
  70. }
  71.  
  72. JsonEdit {
  73. id: jsonEdit
  74. height: 300
  75. width: parent.width
  76. }
  77.  
  78. Rectangle {
  79. id: hint
  80. height: 100
  81. width: parent.width
  82. color: "red"
  83.  
  84. Text {
  85. anchors.fill: parent
  86. wrapMode: Text.WordWrap
  87. text: "<b>Use up and down keys to navigate!</b><br/>"+
  88. "You also might want to modify the <b>MongoDB.name property</b> to your database name "+
  89. "and the <b>MongoCollection.name property</b> to your collection name to see any data"
  90. }
  91. }
  92.  
  93. Row {
  94. spacing: 2
  95.  
  96. Button {
  97. text: "Run MapReduce Demo"
  98. onButtonClicked: {
  99. var map = function() { emit(1,{}) }
  100. var reduce = function( key , values ) { return 123; };
  101. var result = mythings.mapReduce(map, reduce, "testname");
  102.  
  103. console.log( result.find({}).count() )
  104. console.log( Json.JSON.stringify(result.find({}).toArray()) )
  105. listview.model = result.find({}).toModel(listview)
  106. }
  107. }
  108. }
  109. }
  110. }
To copy to clipboard, switch view to plain text mode