Deilan
Deilan

Reputation: 4886

Using RQL filter documents by condition on nested array in RavenDB 4.0+

In RavenDB 4.0+ for a given Sample Northwind database (which is also available at http://live-test.ravendb.net/), what RQL queries one may use to:

  1. Get Orders in which at least one of the Lines has Discount == 0?
  2. Get Orders in which all the Lines have Discount != 0?
  3. Get Orders in which at least one of the Lines has Discount != 0?
  4. Get Orders in which all the Lines have Discount == 0?

Here's a sample document structure:

{
    "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
        },
        {
            "Discount": 0,
            "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
    }
}

I managed to find out some answers only for 1 and 2:

  1. Get Orders in which at least one of the Lines has Discount == 0?
  1. Get Orders in which all the Lines have Discount != 0?

Upvotes: 5

Views: 793

Answers (0)

Related Questions