Skip to main content
 首页 » 编程设计

python之Rethinkdb:从查询中返回多个对象

2024年10月17日6duanxz

我有一个表格,其中有些行如下所示:

{ 
  "id": "12345" 
  "created_date": Fri May 27 2016 22:06:25 GMT+00:00 , 
  "image": true 
 
} { 
  "id": "6789" 
  "created_date": Mon May 30 2016 07:48:35 GMT+00:00 , 
  "video": true 
 
}{ 
  "id": "12345" 
  "created_date": Fri May 21 2016 22:06:25 GMT+00:00 , 
  "image": true 
 
} { 
  "id": "6789" 
  "created_date": Mon May 6 2016 07:48:35 GMT+00:00 , 
  "video": true 
 
} 
etc... 

我想返回具有 "video":true 的最新(最新、最早日期)对象 除此之外,我想返回具有 "image":true 的最新对象。

但是,我想在一个查询中执行此操作,因为这最终将在同一张表上完成。

理想的答案是:

[{ 
      "id": "12345" 
      "created_date": Fri May 27 2016 22:06:25 GMT+00:00 , 
      "image": true 
 
    }, { 
      "id": "6789" 
      "created_date": Mon May 30 2016 07:48:35 GMT+00:00 , 
      "video": true 
 
    }] 

有什么办法吗?

请您参考如下方法:

您可以通过编写类似于 r.expr([query1, query2]) 的内容来合并两个查询,它应该可以工作。