Skip to content

is $lookup required (in lieu of square brackets ala js) to dynamically select object properties? #447

Open
@darrencruse

Description

@darrencruse

i.e. object properties whose names aren't known until run time?

to clarify: in plain javascript if I have something like this:

const json = {
  "esFields": {
    "param1": "esField1.keyword",
    "param2": "esField2.keyword"
  }
}

it's typical to do just json.esFields.param1 if u know the "param1" part ahead of time
but if if u have a variable param whose value is the "param1" then (idiomatically) u switch to json.esFields[param]

In trying to use JSONata to generate some elasticsearch query json I struggled where I was trying to map input parameter names to elasticsearch field names using an object to do the mapping

This is a simplified equivalent of what I was attempting and the error I was getting (where I realized the square brackets seemingly do not/cannot just take a property name string?)
can this be made to work without $lookup?

I did finally get it working using $lookup like this:
working with $lookup

(but in my mind what I was doing seemed simple mostly I just wanted to confirm there wasn't a simple solution that didn't use the $lookup)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions