RethinkDB 查询:如何根据日期范围进行采摘
RethinkDB Query: How to pluck bassed on a date range
给定一个名为 alerts 的 table 和一个名为 database 的数据库,其中包含一个数组
具有名为 History 的日期属性的对象我如何采摘基于
在该日期属性的日期范围内?
使用以下查询,
r.db("database").table("alerts").pluck("history").limit(10000)
我得到类似下面的东西
{
"history": [
{
"text": "text1" ,
"updateTime": Thu Jun 20 2019 01:29:47 GMT+00:00 ,
},
{
"text": "text2" ,
"updateTime": Thu Jun 20 2019 01:24:59 GMT+00:00 ,
},
]
}
{
"history": [
{
"text": "text3" ,
"updateTime": Thu Jun 20 2018 01:29:47 GMT+00:00 ,
},
{
"text": "text4" ,
"updateTime": Thu Jun 20 2018 01:24:59 GMT+00:00 ,
},
]
}
我怎样才能提取名为 history 的子对象,并且只提取 return updateTime 属性特定范围内的历史记录。
例如在 jan/2/2009 到 jan/3/2009
之间
您需要根据时间范围进行过滤,并对嵌套对象使用 pluck。以下是官方文档中有关如何执行此操作的一些示例
r.table("users").filter(function (user) {
return user("subscriptionDate").during(
r.time(2012, 1, 1, 'Z'), r.time(2013, 1, 1, 'Z'));
}).run(conn, callback);
来源:https://www.rethinkdb.com/api/javascript/filter/
r.table('marvel').pluck({'abilities' : {'damage' : true, 'mana_cost' : true}, 'weapons' : true}).run(conn, callback)
给定一个名为 alerts 的 table 和一个名为 database 的数据库,其中包含一个数组 具有名为 History 的日期属性的对象我如何采摘基于 在该日期属性的日期范围内?
使用以下查询,
r.db("database").table("alerts").pluck("history").limit(10000)
我得到类似下面的东西
{
"history": [
{
"text": "text1" ,
"updateTime": Thu Jun 20 2019 01:29:47 GMT+00:00 ,
},
{
"text": "text2" ,
"updateTime": Thu Jun 20 2019 01:24:59 GMT+00:00 ,
},
]
}
{
"history": [
{
"text": "text3" ,
"updateTime": Thu Jun 20 2018 01:29:47 GMT+00:00 ,
},
{
"text": "text4" ,
"updateTime": Thu Jun 20 2018 01:24:59 GMT+00:00 ,
},
]
}
我怎样才能提取名为 history 的子对象,并且只提取 return updateTime 属性特定范围内的历史记录。 例如在 jan/2/2009 到 jan/3/2009
之间您需要根据时间范围进行过滤,并对嵌套对象使用 pluck。以下是官方文档中有关如何执行此操作的一些示例
r.table("users").filter(function (user) {
return user("subscriptionDate").during(
r.time(2012, 1, 1, 'Z'), r.time(2013, 1, 1, 'Z'));
}).run(conn, callback);
来源:https://www.rethinkdb.com/api/javascript/filter/
r.table('marvel').pluck({'abilities' : {'damage' : true, 'mana_cost' : true}, 'weapons' : true}).run(conn, callback)