Data & Backend

Creating Data Models & Fields

This guide walks you through creating Data Models and Fields for your app. Data Models give your app persistent, structured storage — so your users' data is saved reliably and available across sessions.

Creating a New Data Model

Follow these steps to add a Data Model to your application:

1

Open Your App in the Editor

Navigate to your application in Webase and open the Application Editor. You'll see the Chat panel on the left and the Preview panel on the right.

2

Navigate to the Data Models Section

In the editor, look for the Data Models tab or section. This is where you manage all the data collections for your app.

3

Click "New Data Model"

Click the button to create a new model. You'll be prompted to enter a name for your data model.

4

Name Your Model

Enter a descriptive name for your model. For example: "Tasks," "Contacts," "Products," or "Blog Posts." The name should describe the type of records the model will hold.

5

Add Fields

Once your model is created, add fields to define the structure of each record. Each field needs a name and a type. See the field type reference below for guidance on which type to choose.

Naming Conventions

When you create a Data Model, Webase automatically generates a slug from the name you provide. This slug is used as the MongoDB collection name behind the scenes.

  • "Tasks" becomes the slug tasks
  • "Blog Posts" becomes the slug blog-posts
  • "Product Categories" becomes the slug product-categories

Use clear, plural names for your models. This makes it easy to understand what each model contains at a glance.

Field Type Reference

Here's a detailed guide to each field type and when to use it:

  • String — Short text up to a few hundred characters. Use for names, titles, email addresses, phone numbers, or any brief text. Example: a "title" field for tasks.
  • Text — Long-form text with no practical length limit. Use for descriptions, notes, comments, or article content. Example: a "description" field for blog posts.
  • Number — Any numeric value, including decimals. Use for prices, quantities, ratings, scores, or ages. Example: a "price" field for products.
  • Boolean — A true or false value. Use for toggles and flags like "is completed," "is published," or "is featured." Example: a "completed" field for tasks.
  • Date — A calendar date value. Use for due dates, event dates, birthdays, or any date-based information. Example: a "due_date" field for tasks.
  • URL — A web address. Use for website links, profile URLs, or resource references. Example: a "website" field for contacts.
  • Image — An image file that can be uploaded and displayed. Use for profile photos, product images, or thumbnails. Users can upload images directly through your app's interface.
  • Attachment — A general file upload. Use for documents, PDFs, spreadsheets, or any file type. Similar to Image but not limited to visual files.
  • Collaborator — A reference to a user or team member. Use for assigning tasks, tracking ownership, or noting who created a record. Example: an "assigned_to" field for tasks.
  • Single Select — A dropdown with predefined choices. Use when a field should only contain one of several specific values. Example: a "status" field with options "To Do," "In Progress," and "Done."
  • Link to Object — A reference to a record in another Data Model. Use to create relationships between models. Example: linking each "Task" to a "Project." This creates a bidirectional connection that stays in sync automatically.
  • Dynamic — A flexible field that accepts any data type. Use when the structure of the data might vary between records or when you need maximum flexibility.

Setting Up Special Field Types

Image and Attachment Fields

When you add an Image or Attachment field to your model, your app will automatically get upload support for that field. Users can upload files through the generated interface, and the files are stored and served by Webase. Image fields will display a preview of the uploaded image, while Attachment fields show a download link.

Single Select Fields

After creating a Single Select field, you'll need to define the available options. For example, a "priority" field might have the options "Low," "Medium," and "High." These options appear as a dropdown in your app's forms, ensuring consistent data entry.

Link to Object Fields

Link to Object fields create relationships between your Data Models. When you add a Link to Object field, you select which other model it should link to. For example, if you have a "Tasks" model and a "Projects" model, you can add a "project" field (Link to Object) on Tasks that points to Projects. Webase automatically keeps these links in sync — if you delete a project, the linked references on tasks are cleaned up.

Tips for Good Data Model Design

  • Start simple. Begin with the essential fields and add more as your app evolves. You can always add new fields later without losing existing data.
  • Use meaningful names. Name your models and fields clearly so that anyone looking at the data can understand what each piece represents.
  • Choose the right field type. Using the correct type (e.g., Number for prices instead of String) ensures your app can sort, filter, and validate data properly.
  • Use Single Select for constrained values. If a field should only contain certain values (like status or category), use Single Select rather than a free-text String. This prevents typos and inconsistent data.
  • Connect related models with Link to Object. If two types of data are related (Tasks belong to Projects, Orders contain Products), use Link to Object fields to establish the relationship. This enables richer features in your app.

Need a refresher on the basics? See Data Models Overview for an introduction to what Data Models are and how they work. Ready to learn how your app's code interacts with data? Ask the AI in chat — it will generate all the necessary DataService calls for you automatically.