0
我在加入兩個表時遇到了一些問題。使用RethinkDB加入陣列
我有兩個表:
QAS
[{
"course": "swd" ,
"id": "c9b2e8cb-15f9-4f93-b677-6dff2880d383" ,
"number": 1 ,
"questions": [
{
"date": "Wednesday, December 16th, 2015, 11:09" ,
"owner": 4362445 ,
"question": "Could you explain promises?" ,
"questionid": "2766d4bf-fd79-4f94-8d22-788d4e6b89c2" ,
}
] ,
"session": 1 ,
"unit": 1
}]
用戶
[{
"avatar_url": https://avatars.githubusercontent.com/u/4362445?v=3, »
"displayName": "Jamie" ,
"id": 4362445 ,
"oauth_token": "46451371bffea867a71b9cc357eff4fd9a06591e" ,
"role": "student" ,
"team": {
"id": 1729535 ,
"name": "dwa-group-a"
} ,
"username": "Jamiek94"
}]
現在我想加盟(QAS - >問題 - >所有者) (用戶 - > ID),最後將它們壓縮到最大。 所以結果是這樣的:
[{
"course": "swd" ,
"id": "c9b2e8cb-15f9-4f93-b677-6dff2880d383" ,
"number": 1 ,
"questions": [
{
"date": "Wednesday, December 16th, 2015, 11:09" ,
"owner": 4362445 ,
"question": "Could you explain promises?" ,
"questionid": "2766d4bf-fd79-4f94-8d22-788d4e6b89c2" ,
"user" : {
"avatar_url": https://avatars.githubusercontent.com/u/4362445?v=3, »
"displayName": "Jamie" ,
"id": 4362445 ,
"oauth_token": "46451371bffea867a71b9cc357eff4fd9a06591e" ,
"role": "student" ,
"team": {
"id": 1729535 ,
"name": "dwa-group-a"
}
}
] ,
"session": 1 ,
"unit": 1
}]
我使用的查詢是:
r.db('GitSmurf').table('qa').eqJoin(r.row('questions')('owner'), r.db('GitSmurf').table('users'), { index : 'id'})
這導致:
返回沒有結果此查詢
重新思考有一個'union'命令可以幫助:https://rethinkdb.com/api/javascript/union/ – nha