Skip to main content
Altcraft Docs LogoAltcraft Docs Logo
User guide iconUser guide
Developer guide iconDeveloper guide
Admin guide iconAdmin guide
English
  • Русский
  • English
Login
    User documentationGetting StartedFAQAltcraft glossary
      Profiles and databasesarrow
    • Subscription resourcesManaging databasesSubscriber profileProfiles import and data updateScheduled customer data importAutomatic data collectionBulk customers profiles updateDouble opt-in subscriptionSuppression listsProfile relationsProfile history exportProfile exportCreating a static segment based on import resultsHow to open a CSV fileMatchingTypes of fields in the databaseGlobal control groupsSubscription Manager
      Communication channelsarrow
      • Email channelarrow
      • Email: ISP interactions best practicesEmail: sending domain configurationEmail: setting up and using postmastersБыстрый старт
        Push channelarrow
        • Mobile Pusharrow
        • Settings & implementation
            Integrate your app with Altcraftarrow
          • Providers: push message structureProcessing and adding a subscriptionEvent registration
          Web pusharrow
        • Preliminary Settings
            Web browser push configurationarrow
          • Firebase Cloud messagingApple SafariMozilla Services
          Connecting Web Push to a WebsiteTransferring Data to the PlatformWeb Push SDK Methods
            Import of subscriptions from third-party push servicesarrow
          • Migrating push subscriptions from third-party servicesHow to transfer push subscriptions configured for Safari?Migration from OneSignal
      SMS channel
        Creating mailing from scratcharrow
      • EmailSMSWeb PushMobile PushWhatsAppViber*™Руководство: SMS-рассылка через VK NotifyMAX BotMAX GroupNotifyTelegram BotTelegram Group
      Communication Channels WorkflowРуководство: SMS-рассылка через УТШРуководство: push-рассылка через сервис от "Согласие"
      Segmentationarrow
    • Static SegmentsDynamic SegmentsUpdatable Segments
        Segmentation Conditionsarrow
      • Segmentation by Profile dataSegmentation by Interactions with EntitiesSegmentation by Activity of the channelSegmentation by external dataSegmentation by external SQL tablesSegmentation by Profile structure
      Best Send Time (BST)Logical operators "AND" and "OR"Recommendations for working with segments
      Message templatesarrow
      • Working with message templatesarrow
      • Working in the editorEmail-templateSMS templatePush templateMAX templateTelegram templateWhatsApp templateViber™ templateNotify template
        Visual editor for email-templatearrow
      • Visual editor interfaceAdding blocksElements and their settingsCustom blocksStyle managerLayer manager
      Template fragmentsImage galleryContent personalizationCreating tables based on array elementsBlock editor for email template
        Altcraft Variables and Functionsarrow
      • Logical expressions in messagesLoops in messagesMarket variables in templatesUsing the JSONPath functionality
        Dynamic content in messagesarrow
      • Dynamic HTML contentDynamic JSON contentContent from SQL database in templatesDynamic API content
      Importing and exporting a message templateImporting a template from a third-party serviceExporting a template from Pixcraft
      Mailingsarrow
    • Mailings calendarBroadcast mailingsRegular mailingTrigger mailingMultivariate testingMailing testingMailing schedulePlacement mailing
      Campaignsarrow
    • Working with CampaignsLocal control groups (LCG)Stratification Violation ErrorAudience expansionAudience building
      Automation scenariosarrow
    • Managing scenariosNodes of the scenarioClassic marketing scenariosStep-by-step welcome scenario guideScenario for automatic notification of the managerAbandoned cart scenario
      Marketarrow
    • Market settings
        Productsarrow
      • How to create a product manuallyHow to import a product from a fileScheduled product importProduct and SKU SegmentsPreparing the YML file
      OrdersMarket variables in message templateGuide: how to send an order confirmation email
      Loyalty programsarrow
    • Loyalty programsLoyalty integration with external systemsБыстрый стартBasic loyalty program use casesOrder SegmentsPromotion codes
      Reports and analyticsarrow
    • Channel reportTraffic report
        Summary reportarrow
      • Summary report metrics
      Cohorts reportLifetime reportFunnels reportGoals reportAudience growth reportClick map reportLoyalty programs reportBounces reportUndeliveries reportReport on global control groups
      Integrationsarrow
      • Action hooksarrow
      • Altcraft Action HooksAction hooks event typesAction Hook Message StructureJSON batch request (HTTP POST action hook)Message to RabbitMQ brokerMessage to RabbitMQ exchangerMessage to Kafka brokerTest event
        Integration of third-party services using Albatoarrow
      • Connecting Altcraft to Albato Launching the welcome scenario using AlbatoTransmitting event dataSetting app a trigger mailingEvent registrationGoogle Sheets and Altcraft integration AmoCRM and Altcraft integration
      Facebook Ads Manager™Google Ads AudiencesMAXYandex.Audience™VK Ads™Static segment synchronizationYandex AppMetrica™Tilda™Lpgenerator™WhatsAppViber*™ integrationIntegration scopeData Transmitted During SynchronizationNotify
      Weblayersarrow
      • Formsarrow
      • Create a formForm constructorAppearanceActions after form activationData analyticsBinding data channel and formsConditional logic in forms and surveysNPS testing
        Pixelsarrow
      • Goal customer actions and scoring
        Pop-upsarrow
      • Creating and publishing a pop-upSetting up a popup in the code editorManaging pop-ups manually via scriptPopup analyticsGuide: pop-up for push subscriptionsCase: Creating a pop-up with the "Wheel of Fortune" widgetBasic cases of placing a popup via the Tag Manager
        Tag Managerarrow
      • Configuring and installing Tag ManagerTrigger typesVariables typesLinking a pixel and the Tag manager
      Settingsarrow
    • Account settingsCustom linksVirtual sendersSending policiesAudit journalTags FAQ
        Users, groups and accessarrow
      • Two-Factor Authentication (2FA)
        Connectionsarrow
      • Connection to Facebook Ads ManagerConnection to Google AdsConnecting to Yandex.Audience™Connection to 360dialogConnection to EdnaConnection to Devino TelecomConnection to SMSTrafficConnection to VK Ads™Connection to MTS OmniChannelCustom Authentication ConnectionOAuth2 connectionBasic Authentication connectionToken Authentication connectionConnection to RapportoMAX connectionConnection to Notify
      Attribute settings
      API requests: where to startarrow
    • Import or update a profileTrigger mailing launchEngage profile in scenario
      Changelogarrow
    • v2026.1.76v2025.4.75v2025.4.74v2025.3.73v2025.2.72v2025.1.71v2024.4.70v2024.3.69v2024.2.68.2v2024.1.68
    Documentation archivelibrary
  • Segmentation
  • Segmentation Conditions
  • Segmentation by Profile structure

Segmentation by Profile structure

Description​

You can create queries to MongoDB for complex segmentation of profiles by JSON fields.To create a query, set the following conditions for your segment:

  • Selection by — Profile Structure

  • Selection condition — EJSON Request

Next, describe the request in the EJSON format.

Operators​

Various operators are used for an extended JSON database query. You can read more about EJSON for MongoDB in the documentation. Below we will show you how to work with the main operators.

For example, the database has a profile with an additional JSON field — "list":

This field contains the following array:

[
{
"contract_id": 10,
"category": "A",
"payment": 1000
}
]

The tables show queries that will allow you to select a given profile from the database:

Comparison operators​

OperatorDescriptionExample
$eqMatches values that are equal to a specified value.
{
   "list.category": {
      "$eq": "A"
   }
}
$neMatches all values that are not equal to a specified value.
{
   "list.category": {
      "$ne": "B"
   }
}
$gtMatches values that are greater than a specified value.
<br/>   "list.payment": {
      "$gt": 500
   }
}
$gteMatches values that are greater than or equal to a specified value.
{
   "list.payment": {
      "$gte": 1000
   }
}
$ltMatches values that are less than a specified value.
{
   "list.payment": {
      "$lt": 1500
   }
}
$lteMatches values that are less than or equal to a specified value.
{
   "list.payment": {
      "$lte": 1000
   }
}
$inMatches any of the values specified in an array.
{
   "list.contract_id": {
      "$in": [
         10,
         20,
         30
      ]
   }
}
$ninMatches none of the values specified in an array.
{
   "list.contract_id": {
      "$nin": [
         20,
         30,
         40
      ]
   }
}

Logical operators​

OperatorDescriptionExample
$andJoins query clauses with a logical AND returns all documents that match the conditions of both clauses.
{
   "$and": [
      {
         "list.payment": {
            "$gte": 1000
         }
      },
      {
      "_city":      {
            "$eq": "Barcelona"
         }
      }
   ]
}
$notInverts the effect of a query expression and returns documents that do not match the query expression.
{
   "list.category": {
      "$not": {
         "$eq": "D"
      }
   }
}
$orJoins query clauses with a logical OR returns all documents that match the conditions of either clause.
{
   "$or": [
      {
         "list.payment": {
            "$gte": 2000
         }
      },
      {
         "_city": {
            "$eq": "Barcelona"
         }
      }
   ]
}
$norJoins query clauses with a logical NOR returns all documents that fail to match both clauses.
{
   "$nor": [
      {
         "list.payment": {
            "$gte": 1500
         }
      },
      {
         "_city": {
            "$eq": "Barcelona"
         }
      }
   ]
}

$elemMatch​

The $elemMatch operator allows you to select profiles whose array stored in a JSON field contains at least one element that matches all conditions.

Profile#1Profile#2

"list":    [       {       "category":"A",       "payment": 1000    },    {       "category":"B",       "payment": 2000    } ]

"list":    [       {       "category":"B",       "payment": 1500    },    {       "category":"C",       "payment": 2000    } ]

The query will select Profile#1 and Profile#2:

{
"list.category": "B",
"list.payment": 2000
}

The query will only select Profile#1:

{
"list": {
"$elemMatch": {
"category": "B",
"payment": 2000
}
}
}
caution

Only simple data types can be compared. Complex types (objects, arrays) cannot be compared because the preservation of field order in the request and the profile database is not guaranteed.

Example of invalid comparison:

// Comparison of profile JSON field "list"
{
"list": {
"$eq": {
"contract_id": 10,
"category": "A",
"payment": 1000
}
}
}

Instead of comparing entire objects, it is better to compare by keys and their values. For example:

{
"list.category": {
"$eq": "A"
}
}

Date​

Use the {"$dateNowFunc": "0"} argument to specify a date offset in days.

The query will select profiles updated no later than yesterday:

{
"_updatetime": {
"$gte": {
"$dateNowFunc": "-1"
}
}
}

You can also use this function to work with dates stored in JSON fields. For example, the following array is written in the additional profile field "list":

"list":
[
{
"contract_id":10,
"category": "A",
"start_date":"2022-07-01",
"expiration_date":"2022-08-01"
},
{
"contract_id":20,
"category": "B",
"start_date":"2022-06-15",
"expiration_date":"2022-09-15"
}
]

The query will select profiles with which the contract of category "A" was concluded no earlier than a week ago:

{
"list": {
"$elemMatch": {
"category": "A",
"start_date.r": {
"$gte": {
"$dateNowFunc": "-7"
}
}
}
}
}

The query will select profiles with which a category "B" contract has been concluded. In addition, this contract will expire in less than a month:

{
"list": {
"$elemMatch": {
"category": "B",
"expiration_date.r": {
"$lte": {
"$dateNowFunc": "30"
}
}
}
}
}
info

Please note that birthdays, registration dates, as well as dates recorded in additional fields are stored in the platform in the following form:

"date" : {
"r" : ISODate("2020-09-30T07:42:30.501Z"),
"y" : 2020,
"m" : 9,
"d" : 30,
"md" : 930,
"ymd" : 20200930
}

When you write a path to such a field, add an additional key - r. For example date.r.

Last updated on Mar 31, 2026
Previous
Segmentation by external SQL tables
Next
Best Send Time (BST)
  • Description
  • Operators
    • Comparison operators
    • Logical operators
    • $elemMatch
    • Date
© 2015 - 2026 Altcraft, LLC. All rights reserved.