컬렉션 관리 기능 collection-management-functions
쿼리 컬렉션 함수 기본 정보
표현식 언어에서는 컬렉션을 쿼리하기 위한 함수 집합도 소개합니다. 이러한 기능은 아래에 설명되어 있습니다.
다음 예제에서는 푸시 알림 토큰 컬렉션을 포함하는 "LobbyBeacon"이라는 이벤트를 사용합니다. 이 페이지의 예제에서는 아래에 표시된 이벤트 페이로드 구조를 사용합니다.
{
"_experience":{
"campaign":{
"message":{
"profile":{
"pushNotificationTokens":[
{
"token":"token_1",
"application":{
"_id":"APP1",
"name":"MarltonMobileApp",
"version":"1.0"
}
},
{
"token":"token_2",
"application":{
"_id":"APP2",
"name":"MarketplaceApp",
"version":"1.0"
}
},
{
"token":"token_3",
"application":{
"_id":"APP3",
"name":"VendorApp",
"version":"2.0"
}
}
]
}
}
}
},
"timestamp":"1536160728"
}
@event{LobbyBeacon._experience.campaign.message.profile.pushNotificationTokens}을(를) 사용하여 참조됩니다. 여기서 "LobbyBeacon"은 이벤트 이름이고 경로의 나머지 부분은 위에 표시된 구조에 해당합니다.all(<condition>) 함수
all 함수를 사용하면 부울 식을 사용하여 주어진 컬렉션에서 필터를 정의할 수 있습니다.
<listExpression>.all(<condition>)
개념적 예: 모든 앱 사용자 중에서 IOS 13(부울 표현식 “app used == IOS 13”)을 사용하여 앱 사용자를 가져올 수 있습니다. 이 함수의 결과는 부울 표현식(예: 앱 사용자 1, 앱 사용자 34, 앱 사용자 432)과 일치하는 항목을 포함하는 필터링된 목록입니다.
Data Source 조건 활동에서 all 함수의 결과가 null인지 여부를 확인할 수 있습니다. 이 all 함수를 count와 같은 다른 함수와 결합할 수도 있습니다. 자세한 내용은 데이터 Source 조건 활동을 참조하세요.
LobbyBeacon 페이로드를 사용하는 코드 예:
아래 예제에서는 이 페이지 상단에 표시된 이벤트 페이로드를 사용합니다.
예제 1
사용자가 특정 버전의 애플리케이션을 설치했는지 확인하려고 합니다. 이를 위해 버전이 1.0인 모바일 애플리케이션과 연결된 모든 푸시 알림 토큰을 가져옵니다. 그런 다음 count 함수로 조건을 수행하여 반환된 토큰 목록에 하나 이상의 요소가 포함되어 있는지 확인합니다.
count(@event{LobbyBeacon._experience.campaign.message.profile.pushNotificationTokens.all(currentEventField.application.version == "1.0").token}) > 0
결과는 true입니다.
예제 2
여기에서는 count 함수를 사용하여 컬렉션에 푸시 알림 토큰이 있는지 확인합니다.
count(@event{LobbyBeacon._experience.campaign.message.profile.pushNotificationTokens.all().token}) > 0
결과는 true입니다.
count(@event{LobbyBeacon._experience.campaign.message.profile.pushNotificationTokens.token})
식의 결과는 3입니다.
-
all() 함수의 필터링 조건이 비어 있으면 필터가 목록에 있는 모든 요소를 반환합니다. 그러나 컬렉션의 요소 수를 계산하려면 all 함수가 필요하지 않습니다.
-
currentEventField은(는) 이벤트 컬렉션을 조작할 때만 사용할 수 있으며,currentDataPackField은(는) 데이터 소스 컬렉션을 조작할 때 사용할 수 있고currentActionField은(는) 사용자 지정 작업 응답 컬렉션을 조작할 때만 사용할 수 있습니다.
all, first 및 last(으)로 컬렉션을 처리할 때 컬렉션의 각 요소를 하나씩 반복합니다. currentEventField, currentDataPackField 및 currentActionField은(는) 루프가 적용되는 요소에 해당합니다.첫 번째(<condition>) 및 마지막(<condition>) 함수
first 및 last 함수는 필터를 충족하는 목록의 첫 번째/마지막 요소를 반환하면서 컬렉션에서 필터를 정의할 수도 있습니다.
<listExpression>.first(<condition>)
<listExpression>.last(<condition>)
예제 1
이 표현식은 버전이 1.0인 모바일 애플리케이션과 연결된 첫 번째 푸시 알림 토큰을 반환합니다.
@event{LobbyBeacon._experience.campaign.message.profile.pushNotificationTokens.first(currentEventField.application.version == "1.0").token}
결과는 token_1입니다.
예제 2
이 표현식은 버전이 1.0인 모바일 애플리케이션과 연결된 마지막 푸시 알림 토큰을 반환합니다.
@event{LobbyBeacon._experience.campaign.message.profile.pushNotificationTokens.last(currentEventField.application.version == "1.0").token}
결과는 token_2입니다.
at(<index>) 함수
at 함수를 사용하면 색인에 따라 컬렉션의 특정 요소를 참조할 수 있습니다.
색인 0은 컬렉션의 첫 번째 색인입니다.
<listExpression>.at(<index>)
예
이 표현식은 목록의 두 번째 푸시 알림 토큰을 반환합니다.
@event{LobbyBeacon._experience.campaign.message.profile.pushNotificationTokens.at(1).token}
결과는 token_2입니다.
This section contains structured knowledge intended to support interpretation, retrieval, and question answering related to this topic.
For complete understanding, this information should be combined with the documentation on this page. Neither source is intended to stand alone; the page describes the feature, while this section provides additional context that helps disambiguate terminology, intent, applicability, and constraints.
- TL;DR: This page documents the
all(),first(),last(), andat()collection management functions used in the Journey advanced expression editor, illustrated with push notification token payload examples.
Intents:
- Filter a collection of event or data source fields using a boolean condition with
all(<condition>) - Count filtered or unfiltered collection elements using
count()combined with collection functions - Retrieve the first or last matching element of a collection using
first()orlast() - Access a collection element at a specific zero-based index using
at(<index>) - Understand which loop variable (
currentEventField,currentDataPackField,currentActionField) applies to each collection context
Glossary:
- all(condition): Filters a collection and returns all items matching the given boolean expression (product-specific)
- first(condition): Returns the first (most recent for experience events) element in a collection matching the condition (product-specific)
- last(condition): Returns the last (oldest for experience events) element in a collection matching the condition (product-specific)
- at(index): Returns the element at the specified zero-based index of a collection (product-specific)
- currentEventField: Loop variable available only when iterating over event collections (product-specific)
- currentDataPackField: Loop variable available only when iterating over data source collections (product-specific)
- currentActionField: Loop variable available only when iterating over custom action response collections (product-specific)
Guardrails:
- Using experience events in journey expressions/conditions is not supported; consider alternative methods such as computed attributes
currentEventField,currentDataPackField, andcurrentActionFieldare only available inside their respective collection contexts- The
allfunction is not required to count collection elements —count()can be applied directly to the field path - When
all()is called with an empty condition, all elements in the collection are returned
Terminology:
- Canonical name: Collection Management Functions — Acronym: none — variants: collection functions, query collection functions
- Synonyms: “all()” = “collection filter function”; “at()” = “index accessor”
- Do not confuse:
first()(most recent experience event) ≠ first inserted element in general lists
FAQ:
- Q: What is the difference between
all()with an empty condition andall()with a condition? — An emptyall()returns every element; a condition-basedall()returns only elements matching that boolean expression. - Q: How do I count push notification tokens without using
all()? — Callcount()directly on the token field path, e.g.count(@event{LobbyBeacon...pushNotificationTokens.token}). - Q: Which variable do I use to reference the current element when looping over a data source collection? — Use
currentDataPackFieldinsideall(),first(), orlast()on data source collections. - Q: How do I get the second item in a collection? — Use
at(1)because index 0 is the first element. - Q: Why does
last()return the oldest experience event? — Experience events are stored in reverse chronological order, so the last position in the collection corresponds to the oldest event.