简体   繁体   English

使用BaasBox进行NoSQL统计信息类型查询-OrientDB 1.7.10

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

I'm trying out BaasBox v0.9.2 which ships with OrientDB 1.7.10 for a proof of concept web app I want to build. 我正在尝试与OrientDB 1.7.10一起提供的BaasBox v0.9.2,作为我要构建的概念证明Web应用程序。 Premise is fairly simple and adding/querying is very straight forward and simple for single collections. 前提非常简单,添加/查询非常简单,对于单个集合也很简单。 What I'm having difficulty trying to visualize is how to get statistics type information in NoSQL. 我很难形象化的是如何在NoSQL中获取统计信息类型信息。

For example, I have a collection of Contacts (firstName, lastName, address, etc) and a collection of Events (title, date, time, etc) and each Event has an array of attendees. 例如,我有一个联系人集合(名字,姓氏,地址等)和一个事件集合(标题,日期,时间等),每个事件都有一组参与者。

Objects look something like this: 对象看起来像这样:

Contact 联系

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

Event 事件

{
  "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}
  ]
}

What I would like to know is: 我想知道的是:

What was the last event that John Doe attended? John Doe参加的最后一次活动是什么? How many events has John Doe missed? John Doe错过了多少个赛事?

I would prefer an example using Baasbox JS-SDK, but the Plugin-API is also acceptable as is re-organizing the data as nothing is set in stone. 我希望使用使用Baasbox JS-SDK的示例,但是Plugin-API也是可以接受的,因为没有什么困难,因此可以重新组织数据。

you can use any operator/function provided by OrientDB http://www.orientechnologies.com/docs/1.7.8/orientdb.wiki/SQL-Where.html 您可以使用OrientDB提供的任何运算符/功能http://www.orientechnologies.com/docs/1.7.8/orientdb.wiki/SQL-Where.html

In BaasBox you can use the key "fields" for projections and "where" for selections. 在BaasBox中,可以将键“ fields”用于投影,将“ where”用于选择。 So in your case the code should be something like: 因此,在您的情况下,代码应类似于:

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);
        });

The REST API calls are: 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>')

Refs: 参考文献:

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

http://www.baasbox.com/documentation/?javascript#retrieve-documents ( Retrieve documents by a query paragraph) http://www.baasbox.com/documentation/?javascript#retrieve-documents通过查询段落检索文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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