Bubble Docs
  • Introduction
  • New? Start Here
  • What is Bubble?
  • The Glossary
  • User manual
    • Getting started
      • What is Bubble?
      • Building your first app
        • Planning features
        • Database structure
        • Design and UX
        • eCommerce and payments
          • Shopping cart
          • Checkout page
          • One-time payments
          • Subscriptions
          • Marketplace
      • Creating and managing apps
      • The Bubble editor
        • Tabs and sections
          • Design tab
            • The element tree
            • The property editor
          • Workflow tab
          • Data tab
          • Styles tab
          • Plugins tab
          • Settings tab
            • Application settings
              • Custom headers/body
              • Visual settings
              • Social media sharing
              • Translating your app
              • Email settings
              • Collaboration
            • Custom domain and DNS
          • Logs tab
        • Tools
          • Key features
          • The search tool
          • The Issue Checker
          • The element tree
          • The element property editor
          • The debugger
          • Notes
        • Previewing your app
      • Transitioning to Bubble from...
        • JavaScript
        • HTML and CSS
        • SQL
    • Design
      • Elements
        • The element hierarchy
          • The element tree
        • The page
        • Containers
          • Groups
          • Repeating groups
          • Table elements
          • Popups
          • Floating groups
          • Group focus
        • Visual elements
        • Input forms
          • Text and numbers
          • Dates and time
          • File uploads
          • Selection controls
        • Reusable Elements
      • Styling
        • Color variables
        • Font variables
        • Styles
        • Custom Fonts
      • Responsive design
        • Building responsive pages
        • Legacy articles
          • The Basics (Legacy)
          • Building Responsive Pages (Legacy)
          • Migrating Legacy Pages
          • Tips When Designing (Legacy)
      • Templates
      • The Component Library
      • Importing from Figma
    • Data
      • The database
        • Data types and fields
        • Creating, saving and deleting data
        • Finding data
        • Displaying data
        • Protecting data with privacy rules
        • The database editor
        • Export/import data
          • Exporting data
          • Importing data (CSV)
        • Working with location data
        • Using Algolia
        • Database structure by app type
          • Marketplace Apps
          • Directory & Listings Apps
          • Social Network Apps
          • SaaS Apps
          • Project Management Apps
          • CRM Apps
          • Professional Services Apps
          • On-demand Apps
          • Documentation/ CMS Apps
          • Applicant Tracking System (ATS) Apps
          • Portfolio Apps
          • Gallery Apps
          • Online Store / Ecommerce Apps
          • Blog Apps
          • Messaging App
          • Dashboards
          • Building Block Apps
          • Bubble as a backend
      • Files
      • Images
      • Static data
        • App texts (translations)
        • Option sets
      • Temporary data
        • Custom states
        • URL parameters
      • User accounts
        • Authentication plugins
          • Facebook plugin
          • Fitbit plugin
          • Google plugin
          • Instagram plugin
          • LinkedIn plugin
          • Pinterest plugin
          • Slack plugin
          • Wistia plugin
          • YouTube plugin
        • Cookies set by Bubble
      • Time, dates and time zones
    • Logic
      • The frontend and backend
      • Workflows
        • Events
          • Frontend events
            • Recurring workflows
            • Custom events
          • Backend events
            • Database trigger events
        • Actions
        • API Workflows
      • Dynamic expressions
      • Conditions
      • Navigation
        • Single-page applications (SPA)
        • Multi-page applications
        • Page slugs
    • Workload
      • Understanding workload
        • Activity types
        • The workload calculation
        • Client-side and server-side processing
      • Tracking workload
        • Measuring
          • Using App Metrics
        • Monitoring
          • Workload notifications
          • Infinite recursion protection
      • Optimizing workload
        • Optimization framework
        • Optimization checklist
          • Page load
          • Searches
          • Workflows and actions
          • Backend workflows
        • Agency showcases
          • Minimum Studio
          • Neam
          • Support Dept
    • Security
      • Bubble's security features
      • Planning app security
      • Client-side and server-side
      • Bubble account security
      • App security
      • Page security
      • Database security
      • API security
        • API Connector security
        • Data API security
        • Workflow API security
      • Flusk
        • Overview
        • Flusk plan features
        • Getting started with Flusk
        • Flusk security tools
          • The Issues Explorer
          • Issue details
          • Tools and settings
            • Pages rating
            • Database rating
        • Flusk FAQ
      • Cookies
      • Security checklist
    • Publishing your app
      • Web app
      • Native mobile app
        • Global native mobile settings
        • iOS App Store
        • Google Play Store
        • Publishing FAQ
    • AI
      • Generate apps with AI
        • About AI app generation
      • AI page designer
      • Connect to AI agents
    • Maintenance
      • Collaborators
      • Version control
        • Best practices: Version control
        • Transitioning from the legacy version control
        • Terminology: Version control
        • Version Control (legacy)
      • Commenting
      • Database maintenance
        • Copying the database
        • Restoring database backups
        • Bulk operations
          • Bulk operation methods compared
        • Wiping change history
      • Performance
        • Hard limits
        • Capacity Usage (legacy)
        • Notes on queries
      • SEO
        • Introduction to SEO
        • SEO: App
        • SEO: Page
      • Testing and debugging
        • Introduction to testing and debugging
        • The debugger
        • The server logs
        • Supported browsers
      • API workflow scheduler
    • Integrations
      • API
        • Introduction to APIs
          • What is a RESTful API?
        • The Bubble API
          • Bubble API terminology
          • Authentication
            • How to authenticate
            • No authentication
            • As a User
            • As an admin
          • The Data API
            • Data API Privacy Rules
            • Data API endpoints
            • Data API requests
          • The Workflow API
            • Workflow API privacy rules
            • Workflow API endpoints
            • API workflows
              • Creating API workflows
              • Scheduling API workflows
              • Recursive API workflows
              • API Workflow Scheduler
              • Case: Stripe notifications
        • The API Connector
          • Authentication
          • API Connector security
          • API guides
            • OpenAI
              • Authentication
              • Calls
                • ChatGPT
                  • Chat
            • Google Translate
              • How to setup Google API keys
          • Streaming API
        • API security
        • Plugins that connect to APIs
        • API Glossary
      • Plugins
        • What Plugins Can Do
        • Installing and using Plugins
        • Authentication plugins
        • Special Plugins
      • SQL Database Connector
      • Bubble App Connector
      • WorkOS
        • WorkOS SSO
        • WorkOS API
    • Infrastructure
      • Sub-apps
      • Bubble release tiers
      • Hosting and scaling
        • How Bubble hosting works
        • Scaling with Bubble
        • CDN (Cloudflare)
        • Bubble app names
        • Domain and DNS
      • Compliance
        • GDPR
        • SOC 2 Type II
        • HIPAA
        • Other frameworks and standards
    • Bubble for Enterprise
      • Hosting and infrastructure
        • Dedicated instance
          • The Dedicated editor experience
          • Technical specs
          • Main cluster dependencies
          • Customizable options
          • Migration process
            • Pre-migration
            • During migration
            • Post-migration
      • Security and compliance
        • Single sign-on (SSO)
        • GDPR
        • SOC 2 Type II
        • HIPAA
        • Other frameworks
        • Bubble's security features
      • Admin and collaboration
      • Priority support
      • Billing and Payment Guideline for Dedicated Instances
  • Core Reference
    • Using the core reference
    • Bubble's Interface
      • Design tab
      • Design tab (Legacy)
      • Workflow tab
      • Data tab
      • Styles tab
      • Styles tab (Legacy)
      • Plugins tab
      • Settings tab
      • Logs tab
      • Template tab
      • Toolbar
      • Top and context menu options
      • Deployment and version control
        • Deployment & Version Control Dropdown (legacy)
      • Notes
    • Elements
      • General properties
      • General properties (Legacy)
      • Styling properties
      • Styling Properties (Legacy)
      • Responsive Properties
      • Responsive Properties (Legacy)
      • Conditional formatting
      • States
      • Page Element
        • Page Element (Legacy)
      • Visual Elements
      • Containers
      • Container Layout Types
      • Containers (Legacy)
      • Input Forms
      • Reusable Elements
      • Element Templates (legacy)
    • Workflows
    • Events
      • General events
      • Element events
      • Custom events
      • Recurring event
      • Database trigger event
    • Actions
      • Account
      • Navigation
      • Data (things)
      • Email
      • Element
      • Custom
    • Data
      • Data Sources
      • Operators and comparisons
      • Search
      • Privacy
    • Styles
    • API
      • The Bubble API
        • The Data API
          • Authentication
          • Data API endpoints
          • Data API requests
        • The Workflow API
      • The API Connector
        • Authentication
        • Adding calls
    • Bubble-made Plugins
      • AddtoAny Share Buttons
      • Airtable
      • API Connector
      • Blockspring
      • Box
      • Braintree
      • Bubble App Connector
      • Chart.js
      • Circle Music Player
      • Draggable Elements
      • Dropzone
      • Facebook
      • Fitbit
      • Full Calendar
      • Google
      • Google Analytics
      • Google Optimize
      • Google Places
      • Ionic Elements
      • iTunes
      • Slidebar Menu
      • LinkedIn
      • Localize Translation
      • Mixpanel
      • Mouse & Keyboard Interactions
      • Multiselect Dropdown
      • Progress Bar
      • Rich Text Editor
      • Rich Text Editor (Legacy)
      • Screenshotlayer
      • SelectPDF
      • Slack
      • Segment
      • Slick Slideshow
      • SQL Database Connector
      • Star Rating
      • Stripe
      • Tinder-like Element
      • Twitter
      • YouTube
      • Zapier
    • Application Settings
      • App plan
      • General
      • Domain / email
      • Languages
      • SEO / metatags
      • API
      • Collaboration
      • Sub-apps
      • Versions
  • Account & Marketplace
    • Account and billing
      • Pricing and plans
        • Plans and billing
        • Billing cycle
        • FAQ: Pricing and Workload
      • Account Management
      • Building Apps for Others
      • Selling on the Marketplace
      • Plans & Billing (legacy)
    • Official Bubble Certification
      • Hiring certified developers
    • Building Plugins
      • The Plugin Editor
      • General Settings
      • Updating to Plugin API v4
      • Adding API Connections
      • Building Elements
      • Building Actions
      • Loading Data
      • Publishing and versioning
      • Github Integration
    • Building Templates
    • Application and data ownership
    • Marketplace policies
    • Bug reports
  • Beta features
    • About the Beta features section
    • Native mobile apps 🔒
      • Introduction
        • What is a native mobile app?
        • Native mobile vs. web development
        • Differences in native and web elements
        • Native mobile app terminology
      • Building
        • Views and navigation
        • Native mobile actions
        • Components and gestures
        • Device resources
          • Location services
          • Camera/photo library
      • Previewing
      • Publishing
Powered by GitBook
On this page
  • Finding data
  • Sorting the results
  • The difference between a list and a single thing
  • Loading a single record from a list
  • Turning a single record into a list
  • Other data sources
  • Other ways to learn

Was this helpful?

  1. User manual
  2. Data
  3. The database

Finding data

This section covers how to search for data using constraints

Last updated 10 months ago

Was this helpful?

This section takes a long-form look at how searches in Bubble work. To see the the more concise and technical complete list of settings, constraints and operators, you can check out our .

Having added and updated data in our database, we'll also need a way search for that data and display it around our app.

Finding data

Whenever you need to find some data in the database, you can perform a search using the Do a search for . This lets you set up a dynamic query to the database with specific constraints, and Bubble returns all things of that data type that match the constraints. You can only search for one data type at a time, such as Users.

Let's say you want to search for all users who have the name John. We can set up the Do a search for function like the example below.

Data sources like Do a search for are one of the building blocks in dynamic expressions. To read more about how to work with expressions, check out our dedicated article on the subject: Article:

First, we set the Type of content to User and in the Data source dropdown we pick Do a search for:

Then we set up a constraint which instructs Bubble to only return users that have the name John. The result will always be a list, even if it contains just one thing.

This is the basic way that database queries work: we tell Bubble what kind of data to search for, and then provide one or more constraints that each thing in the returned list needs to match. We can use this logic to find data in all sorts of scenarios:

  • To display the results on a screen

  • As part of a workflow (for example if we want to make changes to one or more things)

  • As part of a

In the example above, we used a static value as a constraint: the name John. We can also set this up as a dynamic value. For example, we could change the condition to ask for the value of an input field instead. This would let your users type in a name and search the database for users that match:

Element data sources using Do a search for are synchronised with the database in real-time. This means that any changes happening in the database, even if made by another user, will be immediately visible in your app.

There's no need to manually update searches. The exception is if the initial search was fetched in a workflow.

Sorting the results

Sometimes you'll want to sort the result in a specific way, such as showing users in alphabetical order or tasks by their priority or deadline. This can be used to display the records in a list, or it can be used to find a specific record. For example, if you want to load the last user that was created in your database, you can sort the list by creation date and isolate the newest user with the first item or last item operator (depending on the sorting order).

You can set the sort order when you perform a search.

In some cases you will be referring to a list that's not loaded from a search, or where for some reason you need to apply the sorting after another operator in the expression. In that case you can use the sorted operator.

The difference between a list and a single thing

Whenever you perform a search, the result will be a list – even if it only returns one thing (meaning it's a list with a count of one, but still a list).

Loading a single record from a list

Whenever you set up a data source that returns a list, such as Do a search for, Bubble and expression that expect a single item will return an error in the . In cases like this, you will need to instruct Bubble to load one of the records in the list. You do this by adding another operator in the data source expression:

  • First item will return the first item in the list. What item that will be depends on how the list is sorted. The default sorting is by creation date.

  • Last item will return the last item in the list. What item that will be depends on how the list is sorted. The default sorting is by creation date.

  • Random item will return a item from the list.

  • Item #: will return a single item as specified by its index number in the list. This operator requires you to also define a number, such as Item 5.

By combining search constraints with the first item operator you can often reach the exact thing you were looking for. For example, you could search for users and use the Email field as a constraint. Since emails are unique, you can be sure to find the right record by providing the email address of an existing user. If you then apply the first item to the list of results, you will have turned the list into a single thing.

Turning a single record into a list

Sometimes you'll need to go the other way and turn a single item into a list, even if that list still only contains the one record. To do this, use the operator.

Other data sources

Searching for data in the database with Do a search for is one way of finding data.

Data source
Description
Returns

Do a search for

Searches the database using constraints.

A list of things

Current user

The user currently using the app

One thing

Current page thing

The database record currently loaded onto the page using the Go to page action.

One thing

Get data from page URL

Getting a thing from a URL parameter that contains a unique ID.

One thing

Things's X

Getting a thing from a field saved on another thing, such as Current User's Company

A list or a single item, depending on the field

Other ways to learn

Core reference
Video lessons

Bubble has two ways of handling database records: as single items or as a list. It's important to understand this distinction, because the two are treated differently. For example, when you , a element will expect a single thing, while a will expect a list of things.

group
repeating group
Searching
How to use search constraints
How to use the Do a search for data source
core reference entry on searches
Dynamic expressions
In this example we are searching for users named John.
In this example we are searching for a dynamic value from an input field called Input search by name. By referring to that value as a search, we can let our users specify what to search for.
In this screenshot we are sorting users by their name.
In this example we are using another repeating group as the data source and then applying sorting on that list.
In this example we are taking the User loaded into a group called Group User and turning it into a list. The list will still contain just one record, but Bubble will treat it as a last. In the example this makes it a valid data source for a repeating group.