Uploaded image for project: 'Couchbase Documentation'
  1. Couchbase Documentation
  2. DOC-9073

Add OBJECT_FILTER function

    XMLWordPrintable

Details

    • Improvement
    • Resolution: Won't Fix
    • Minor
    • None
    • None
    • None
    • 1

    Description

      New OBJECT_FILTER function that returns the nested fields that match the supplied pattern retaining the path structure.

      OBJECT_FILTER ( expression [, options])

      expression - resolves to the object on which to apply the filtering

      options:

      "pattern" - string, the pattern to match

      "regex" - boolean, if pattern is a plain string (false) or a regular expression (true, default)

      "arraysubscript" - TRUE (default) / FALSE indicating whether or not to include array subscripts in field names prior to applying the filter.  (See https://issues.couchbase.com/browse/DOC-8641 information for OBJECT_PATHS for examples.)

      "composites" - TRUE (default) / FALSE indicating whether or not the names matched against should include values that will also be broken down further. (See DOC-8541 / OBJECT_PATHS for examples.)

      "patternspace"

      String literal "field" indicating the pattern is matched against individual field names or "path" (default) indicating the pattern is matched against composite path names.

      Example:

       select object_filter(t,{"pattern":"Business service"})  from `travel-sample` t where type = 'hotel' limit 2;
      {
      ...
          "results": [
          {
              "$1": {
                  "reviews": [
                      {
                          "ratings": {
                              "Business service (e.g., internet access)": 4
                          }
                      }
                  ]
              }
          },
          {
              "$1": null
          }
          ],
          "status": "success",
       
      ...

      Example using OBJECT_PATHS to determine the full field path names:

       

      select object_paths(t)  from `travel-sample` t where type = 'hotel' limit 1;
      {
      ...
          "results": [
          {
              "$1": [
                  "address",
                  "alias",
                  "checkin",
                  "checkout",
                  "city",
                  "country",
                  "description",
                  "directions",
                  "email",
                  "fax",
                  "free_breakfast",
                  "free_internet",
                  "free_parking",
                  "geo",
                  "geo.accuracy",
                  "geo.lat",
                  "geo.lon",
                  "id",
                  "name",
                  "pets_ok",
                  "phone",
                  "price",
                  "public_likes",
                  "reviews",
                  "reviews[0].author",
                  "reviews[0].content",
                  "reviews[0].date",
                  "reviews[0].ratings",
                  "reviews[0].ratings.Cleanliness",
                  "reviews[0].ratings.Location",
                  "reviews[0].ratings.Overall",
                  "reviews[0].ratings.Rooms",
                  "reviews[0].ratings.Service",
                  "reviews[0].ratings.Value",
                  "reviews[1].author",
                  "reviews[1].content",
                  "reviews[1].date",
                  "reviews[1].ratings",
                  "reviews[1].ratings.Cleanliness",
                  "reviews[1].ratings.Location",
                  "reviews[1].ratings.Overall",
                  "reviews[1].ratings.Rooms",
                  "reviews[1].ratings.Service",
                  "reviews[1].ratings.Value",
                  "reviews[1].ratings.`Business service (e.g., internet access)`",
                  "reviews[1].ratings.`Check in / front desk`",
                  "state",
                  "title",
                  "tollfree",
                  "type",
                  "url",
                  "vacancy"
              ]
          }
          ],
      ...

       

      select object_filter(t,{"pattern":"reviews[1].ratings.Service","regex":false})  from `travel-sample` t where type = 'hotel' limit 1;
      {
      ...
          "results": [
          {
              "$1": {
                  "reviews": [
                      {
                          "ratings": {
                              "Service": 3
                          }
                      }
                  ]
              }
          }
          ],
       
      ...

       

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              amarantha.kulkarni Amarantha Kulkarni (Inactive)
              Donald.haggart Donald Haggart
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes

                  PagerDuty