微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决在 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 举报,一经查实,本站将立刻删除。