要转换为整数并插入到 rethinkdb 的事件类型
event type to convert as integer and insert to rethinkdb
这是我为每一个活动准备的信息。我怎样才能只收集一种类型的数据(字符串)并将其赋值为 1,同时将值 1 插入到 rethinkdb,并更新它的总值
示例数据 ---- 仅将 "event":"click" 作为整数值 1 并作为 1 插入数据库并更新总值,如 total_click
{
"message_ver": "2011-03-17",
"data":{
"chan":"chan-552a4",
"device":"mob",
"event":"click",
"type":"ad",
"ip":"95.195.139.177",
"user_agent":"Mozilla/5.0 [FB_IAB/FB4A;FBAV/31.0.0.20.13;]",
"content_version":"ver-5534bb69cbeb1",
"referrer":"http://vlt.com",
"r_type":"ad"
}
}
看来你想要的是让每个 document/row 代表不同类型的事件。如果数据库中不存在该事件类型,您似乎想要将新文档插入数据库并添加计数为 1 的 total_event
属性。如果该事件类型已经存在,您可能想要增加该文档的总数。
在这种情况下,文档将具有以下结构:
{
event: 'click'
total_event: 1
}
因此,您可以使用 branch
命令查看是否存在具有该事件名称的文档,并且它们 insert
或 update
文档取决于结果:
r.expr({ "data":{ "event":"click" }})
.do(function (_row) {
return r.branch(
// Check if there is a row with an `event` property equal to our data.event
r.table('29929310').filter({
event: _row('data')('event')
}).count().gt(0),
// If there is, add 1 to the `total` property
r.table('29929310').update(function (_row1) {
return { total: _row1('total').add(1) };
}),
// If there isn't, insert a new document with a total of `1`
r.table('29929310').insert({
event: _row('data')('event'),
total: 1
})
)
})
这是我为每一个活动准备的信息。我怎样才能只收集一种类型的数据(字符串)并将其赋值为 1,同时将值 1 插入到 rethinkdb,并更新它的总值 示例数据 ---- 仅将 "event":"click" 作为整数值 1 并作为 1 插入数据库并更新总值,如 total_click
{
"message_ver": "2011-03-17",
"data":{
"chan":"chan-552a4",
"device":"mob",
"event":"click",
"type":"ad",
"ip":"95.195.139.177",
"user_agent":"Mozilla/5.0 [FB_IAB/FB4A;FBAV/31.0.0.20.13;]",
"content_version":"ver-5534bb69cbeb1",
"referrer":"http://vlt.com",
"r_type":"ad"
}
}
看来你想要的是让每个 document/row 代表不同类型的事件。如果数据库中不存在该事件类型,您似乎想要将新文档插入数据库并添加计数为 1 的 total_event
属性。如果该事件类型已经存在,您可能想要增加该文档的总数。
在这种情况下,文档将具有以下结构:
{
event: 'click'
total_event: 1
}
因此,您可以使用 branch
命令查看是否存在具有该事件名称的文档,并且它们 insert
或 update
文档取决于结果:
r.expr({ "data":{ "event":"click" }})
.do(function (_row) {
return r.branch(
// Check if there is a row with an `event` property equal to our data.event
r.table('29929310').filter({
event: _row('data')('event')
}).count().gt(0),
// If there is, add 1 to the `total` property
r.table('29929310').update(function (_row1) {
return { total: _row1('total').add(1) };
}),
// If there isn't, insert a new document with a total of `1`
r.table('29929310').insert({
event: _row('data')('event'),
total: 1
})
)
})