rethinkdb,我怎么能通过一个特别的值 "array index" 来提取结果?
rethinkdb, How could I pluck the result by a value in particular "array index"?
示例数据
[
{
"createdDate": 1508588333821,
"data": {
"image_extension": "png",
"name": "Golden",
"qty": 1,
"remark": "#296-2",
"status": "RETURN",
"owner": [
{
"name": "app1emaker",
"location": 1
},
{
"name": "simss92_lmao",
"location": 31
}
]
},
"deleted": false,
"docId": 307,
"docType": "product",
"id": "db0131f9-9359-4aa3-b6ed-cd9f3ff4aa3e",
"updatedDate": 1553155281691
},
{
"createdDate": 1508588333324,
"data": {
"image_extension": "png",
"name": "Golden",
"qty": 1,
"remark": "#296-2",
"status": "DISCARD",
"owner": [
{
"name": "At533",
"location": 7
},
{
"name": "madsimon",
"location": 64
},
{
"name": "boyboy96",
"location": 1
},
{
"name": "xinfengCN",
"location": 5
}
]
},
"deleted": false,
"docId": 308,
"docType": "product",
"id": "3790bdaa-5347-4ab0-8149-37332c23c6ea",
"updatedDate": 1554555231691
},
...
...
]
并且说,我只想 select 数组索引 0 上的 data.owner(或者我应该说 data.owner[0]),它们是
{
"name": "app1emaker",
"location": 1
}
和
{
"name": "At533",
"location": 7
}
在这种情况下。我在下面有一个失败的代码。
r.db('carbon').table("items").pluck(['id', 'docId', 'createdDate',{data:{name: true, owner:[0]}}])
我看到对于某些函数,如 orderBy,rethinkdb 允许使用 orderBy(r.row('data')('owner')(0)('name'))用于访问嵌套对象,但我不知道如何为采摘做这个?谁能给我一些提示?
非常感谢
pluck 无法做到这一点,但您可以退而求其次使用 map:
r.db("carbon").table("items").map(function(doc){
return {
"id": doc("id"),
"docId": doc("docId"),
"createdDate": doc("createdDate"),
"data": {
"name": doc("data")("name"),
"owner": doc("data")("owner")(0)
}
}
})
示例数据
[
{
"createdDate": 1508588333821,
"data": {
"image_extension": "png",
"name": "Golden",
"qty": 1,
"remark": "#296-2",
"status": "RETURN",
"owner": [
{
"name": "app1emaker",
"location": 1
},
{
"name": "simss92_lmao",
"location": 31
}
]
},
"deleted": false,
"docId": 307,
"docType": "product",
"id": "db0131f9-9359-4aa3-b6ed-cd9f3ff4aa3e",
"updatedDate": 1553155281691
},
{
"createdDate": 1508588333324,
"data": {
"image_extension": "png",
"name": "Golden",
"qty": 1,
"remark": "#296-2",
"status": "DISCARD",
"owner": [
{
"name": "At533",
"location": 7
},
{
"name": "madsimon",
"location": 64
},
{
"name": "boyboy96",
"location": 1
},
{
"name": "xinfengCN",
"location": 5
}
]
},
"deleted": false,
"docId": 308,
"docType": "product",
"id": "3790bdaa-5347-4ab0-8149-37332c23c6ea",
"updatedDate": 1554555231691
},
...
...
]
并且说,我只想 select 数组索引 0 上的 data.owner(或者我应该说 data.owner[0]),它们是
{
"name": "app1emaker",
"location": 1
}
和
{
"name": "At533",
"location": 7
}
在这种情况下。我在下面有一个失败的代码。
r.db('carbon').table("items").pluck(['id', 'docId', 'createdDate',{data:{name: true, owner:[0]}}])
我看到对于某些函数,如 orderBy,rethinkdb 允许使用 orderBy(r.row('data')('owner')(0)('name'))用于访问嵌套对象,但我不知道如何为采摘做这个?谁能给我一些提示? 非常感谢
pluck 无法做到这一点,但您可以退而求其次使用 map:
r.db("carbon").table("items").map(function(doc){
return {
"id": doc("id"),
"docId": doc("docId"),
"createdDate": doc("createdDate"),
"data": {
"name": doc("data")("name"),
"owner": doc("data")("owner")(0)
}
}
})