我正在尝试与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(通过查询段落检索文档)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句