Oliver's Blog

Querying a MongoDB collection using DevExtreme data store load parameters

I have been working on a sample for a little while now that shows the use of the DevExtreme UI widgets in the context of a real-world architecture. This sample is quite complex and will be the subject of a number of future posts, but it isn't complete yet. Meanwhile, as part of the work, I implemented query logic that runs queries against a MongoDB collection and uses the load options supported by our CustomStore to parameterize the queries. If you are using MongoDB for data storage, you can take advantage of this code to automatically run the dynamic queries generated by our complex UI widgets.

const MongoClient = require("mongodb").MongoClient;
const query = require("devextreme-query-mongodb");

async function queryData() {
  MongoClient.connect("mongodb://localhost:27017/testdatabase", (err, db) => {
    const results = await query(db.collection("values"), {
      // This is the loadOptions object - pass in any valid parameters
      take: 10,
      filter: [ "intval", ">", 47 ],
      sort: [ { selector: "intval", desc: true }]

    // Now "results" contains an array of ten or fewer documents from the 
    // "values" collection that have intval > 47, sorted descendingly by intval.

The code is available now in this github repository: https://github.com/oliversturm/devextreme-query-mongodb

Please check out the readme on the repository page, it has details on installation of the npm module. Please report issues, if you find them, and feel free to ask if something isn't clear to you!

Published Feb 09 2017, 01:03 PM by
Filed under: ,
Bookmark and Share


Mo cisse


How can insert/update/delete mongodb data ?

February 9, 2017 7:36 AM

Oliver Sturm (DevExpress)

I would recommend doing that with the "mongodb" package directly, and my larger sample does it that way. But in contrast to querying, there is nothing technically complicated or DevExtreme-specific to that part of the application logic.

Here's the MongoDB tutorial on basic operations like insert/update/delete: docs.mongodb.com/.../insert

February 9, 2017 7:49 AM

Chat is one of the many ways you can contact members of the DevExpress Team.
We are available Monday-Friday between 7:30am and 4:30pm Pacific Time.

If you need additional product information, write to us at info@devexpress.com or call us at +1 (818) 844-3383


DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, Delphi, HTML5 or iOS & Android development. Whether using WPF, ASP.NET, WinForms, HTML5 or Windows 10, DevExpress tools help you build and deliver your best in the shortest time possible.

Copyright © 1998-2018 Developer Express Inc.
All trademarks or registered trademarks are property of their respective owners