簡體   English   中英

使用BaasBox進行NoSQL統計信息類型查詢-OrientDB 1.7.10

[英]NoSQL statistics type query with BaasBox - OrientDB 1.7.10

我正在嘗試與OrientDB 1.7.10一起提供的BaasBox v0.9.2,作為我要構建的概念證明Web應用程序。 前提非常簡單,添加/查詢非常簡單,對於單個集合也很簡單。 我很難形象化的是如何在NoSQL中獲取統計信息類型信息。

例如,我有一個聯系人集合(名字,姓氏,地址等)和一個事件集合(標題,日期,時間等),每個事件都有一組參與者。

對象看起來像這樣:

聯系

{
  "firstName": "John",
  "lastName": "Doe",
  "appId": "64f00bcb-cc04-4ed9-89fc-3b9b1a448dae"
}

事件

{
  "title": "Some Event",
  "eventDate": "2015-02-24 04:46 PM",
  "isoDate": "2015-02-24T20:46:00.000Z",
  "appId": "64f00bcb-cc04-4ed9-89fc-3b9b1a448dae",
  "attendees": [
        {"contactId": "c8ae2767-5fe5-4d41-ad6a-b10bd6e62f03", "attended": true},
        {"contactId": "eacff8ff-b691-4d82-9429-898a097ea43a", "attended": true},
        {"contactId": "70ab166c-c0a0-488a-9d5f-6f0b70a32125", "attended": false},
        {"contactId": "34944c69-ebdb-49c6-bd1b-cdb0d191f124", "attended": true},
        {"contactId": "8907e99e-96d6-46e9-a76f-1f9ce7f760d3", "attended": true}
  ]
}

我想知道的是:

John Doe參加的最后一次活動是什么? John Doe錯過了多少個賽事?

我希望使用使用Baasbox JS-SDK的示例,但是Plugin-API也是可以接受的,因為沒有什么困難,因此可以重新組織數據。

您可以使用OrientDB提供的任何運算符/功能http://www.orientechnologies.com/docs/1.7.8/orientdb.wiki/SQL-Where.html

在BaasBox中,可以將鍵“ fields”用於投影,將“ where”用於選擇。 因此,在您的情況下,代碼應類似於:

BaasBox.loadCollectionWithParams("Event", 
        {
         fields:"max(eventDate) as last_date", //or count(*) as times
         where:"attendees contains (attended=true and contactId='<john_contact_id>')"
        })
        .done(function(res) {
                 console.log("res ", res);
        })
        .fail(function(error) {
                console.log("error ", error);
        });

REST API調用為:

GET /document/event?fields=max(eventDate) as last_date&where=attendees contains (attended=true and contactId='<john_contact_id>')

GET /document/event?fields=count(*) as times&where=attendees contains (attended=true and contactId='<john_contact_id>')

參考文獻:

http://www.orientechnologies.com/docs/1.7.8/orientdb.wiki/SQL-Where.html

http://www.baasbox.com/documentation/?javascript#retrieve-documents通過查詢段落檢索文檔

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM