在 RavenDB 4.0+ 的嵌套数组上按条件使用 RQL 过滤文档

问题描述

在 RavendB 4.0+ 中,对于给定的 Sample Northwind database(也可从 http://live-test.ravendb.net/ 获得),RQL 查询可能用于:

  1. 获取Orders,其中至少一个Linesdiscount == 0
  2. 获得Orders,其中所有Lines都有discount != 0
  3. 获取Orders,其中至少一个Linesdiscount != 0
  4. 获得Orders,其中所有Lines都有discount == 0

这是一个示例文档结构:

{
    "Company": "companies/85-A","Employee": "employees/5-A","Freight": 32.38,"Lines": [
        {
            "discount": 0,"PricePerUnit": 14,"Product": "products/11-A","ProductName": "Queso Cabrales","Quantity": 12
        },{
            "discount": 0,"PricePerUnit": 9.8,"Product": "products/42-A","ProductName": "Singaporean Hokkien Fried Mee","Quantity": 10
        },"PricePerUnit": 34.8,"Product": "products/72-A","ProductName": "Mozzarella di Giovanni","Quantity": 5
        }
    ],"OrderedAt": "1996-07-04T00:00:00.0000000","RequireAt": "1996-08-01T00:00:00.0000000","ShipTo": {
        "City": "Reims","Country": "France","Line1": "59 rue de l'Abbaye","Line2": null,"Location": {
            "Latitude": 49.25595819999999,"Longitude": 4.1547448
        },"PostalCode": "51100","Region": null
    },"ShipVia": "shippers/3-A","ShippedAt": "1996-07-16T00:00:00.0000000","@Metadata": {
        "@collection": "Orders","@flags": "HasRevisions","@id": "orders/1-A","@last-modified": "2018-07-27T12:11:53.0447651Z","@change-vector": "A:417-EKrWjfz5kESi6lp7Nf442Q","@index-score": 1
    }
}

我设法找到了仅适用于 1 和 2 的一些答案:

1.

  • from Orders where Lines[].discount == 0
  • from Orders where Lines[].discount IN (0)
  • from Orders where Lines[].discount ALL IN (0)
  • from Orders where Lines[].discount != 0

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)