在 rethinkdb 中制定查询

formulate query in rethinkdb

我在 Rethinkdb 中有下一篇文档。

{
  "id": 678 ,
  "author": 0 ,
  "body":  "<p>text</p>" ,
  "category":  "category" ,
  "optionlist": {
                  "option_A": "text 1" ,
                  "option_B": "text 2" ,
                  "option_C": "text 3" 
                } ,
  "rank": 4 ,
  "array": [
             "tag 1" ,
             "tag 2"
           ] ,
}

我需要在 rethinkdb 中进行查询,您只能在其中获取此查询:

"option_A": "text 1" 

还有另一个查询,您只能在其中获取此查询:

"tag 1"

是这样的吗?

r.db('myDataBase').table('myTable').pluck('id','optionlist').filter({article_id:678})

我假设你的意思是 "only the first index in the embedded array" 并且 article_id: 678 将是 optionList:

中嵌入的键值对之一
r.db('myDataBase').table('myTable')('optionList').filter({article_id:678})

然后是另一个结果:

r.db('myDataBase').table('myTable')('array').nth(0)

好的,假设有 2 个不同的请求,第一个请求:

r.db('your_db').table('your_table').filter({id:678})('optionlist').pluck('option_A')

Obs: 如果你有文档的 'id',最好使用 .get() 而不是 .filter(),像这样:

r.db('your_db').table('your_table').get(678)('optionlist').pluck('option_A')

对于第二个请求,您需要:

r.db('your_db').table('your_table').get(678)('array').nth(0)

希望对您有所帮助! 干杯