-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
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)"] }