Skip to content

Query virtual attributes #17

@Speedy37

Description

@Speedy37

Goal: being able to answer to:

  • give me all persons with a least 3 cats
  • give me the latest version of a document for each distinct document theme
  • give the number of cats each persons possess and order them by that number.

Solution: virtual attributes

A virtual attribute is a specially named attribute that represent a computed value and can be used as any other attribute in query (for both conditions and scope)

A virtual attribute can only return a single value.

The $count virtual attribute

Gives the number of values hold by an attribute. If the attribute is sigle value, gives 1 if the value exists, 0 otherwise.

Syntax: $count(attribute)

The range selection virtual attribute

For a set of objets, objects are grouped by a set of attributes then for each group ordered inside it.

Syntax:

  • $isLast(attribute ordering) / group by attribute: true if it's the last value in the ordered set of objects optionally grouped by a set of attributes
  • $isFirst(attribute ordering) / group by attribute: true if it's the first value in the ordered set of objects optionally grouped by a set of attributes

Examples:

  • { $instanceOf: "Person", "$count(_cats)": { $gte: 3 } }
  • { $instanceOf: "Document", "$isLast(+_date) / _theme": true }
  • { scope: ["+$count(_cats)"] }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions