简体   繁体   中英

Retrieving data from MongoDB with ExtJS using the REST API

For the need of a simple demonstrator, I've created a simple grid panel in ExtJS, and now i'm trying to fill it with data coming from MongoDB. I heard about Node.JS and stuff but there I just want to use the REST API of MongoDB to retrieve the data. Note : I'm new in ExtJS and REST request.

My problem is that when loading my page, there is no panel created and firebug tells me : ""NetworkError: 400 Bad Request - http://xxx.xxx.xx.xx:28017/mydb/device/find?_dc=1374225874880&page=1&start=0&limit=25 ""

If I copy and paste the URL http://xxx.xxx.xx.xx:28017/mydb/device/find?_dc=1374225874880&page=1&start=0&limit=25 I can see the data, so that means that the Mongo data are accessible through URL. Note that I dont' know where the "page=1&start=0&limit=25" param of the URL comes from, it wasn't implemented by me.

My code that is supposed to load the data is in my Store component of my MVC :

Ext.define('AM.store.Users', {
extend: 'Ext.data.Store',
model: 'AM.model.User',
autoLoad: true,
proxy: {
    type: 'rest',
url: 'http://xxx.xxx.xx.xx:28017/mydb/device/find',

    reader: {
        type: 'json',
        root: 'rows',
    idProperty: '_id'

    }
}
});

And this is what shows the Mongo URL :

{
"offset" : 0,
"rows": [
 { "_id" : "SheevaPlug", "manufacturer" : "GlobalScale" }
],

"total_rows" : 1 ,
"query" : {} ,
"millis" : 0
}

The mapping in the Model seems correct too :

Ext.define('AM.model.User', {
extend: 'Ext.data.Model',
fields: ['_id', 'manufacturer']
});

Thanks by advance if you can help me ! Cheers,

Vincent

使用Node.js创建将与Sencha一起调用的MongoDB Web服务。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM