【问题标题】:NoSQL statistics type query with BaasBox - OrientDB 1.7.10使用 BaasBox 进行 NoSQL 统计类型查询 - OrientDB 1.7.10
【发布时间】:2015-03-02 14:58:43
【问题描述】:

我正在尝试使用 OrientDB 1.7.10 附带的 BaasBox v0.9.2 来构建我想要构建的概念验证网络应用程序。前提相当简单,添加/查询对于单个集合来说非常直接和简单。我难以想象的是如何在 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 baasbox nosql


    【解决方案1】:

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

    在 BaasBox 中,您可以使用键“字段”进行投影,使用“位置”进行选择。 所以在你的情况下,代码应该是这样的:

    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通过查询检索文档段落)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多