Yapay Zeka Ajanları
n8n Learning Path
CHAPTER 07Intermediate ~75 min

Database Integrations

Working with PostgreSQL, MySQL, MongoDB, Airtable and Notion. CRUD, queries and transactions.

In this chapter

Your automations' memory lives in databases. Writing a lead into a CRM, pulling an order status from PostgreSQL, reading a rule from Notion — all of it goes through database nodes. In this chapter you will meet n8n's 5 main database/storage integrations (PostgreSQL, MySQL, MongoDB, Airtable, Notion), and learn CRUD operations, upsert patterns and sensitive-data handling.

Topics

  • PostgreSQL and MySQL: connections and queries
  • Insert, Update, Delete, Upsert
  • MongoDB: document-oriented data
  • Airtable: tables, records, views
  • Notion: databases and pages
  • Masking sensitive data

PostgreSQL and MySQL: connect and query

For relational databases, n8n provides Postgres and MySQL nodes. Set up Credentials with host/port/database/user/password (SSL is a must in production). The node's Operation: Execute Query (free SQL — most powerful, but parameter safety matters), Insert/Update/Delete (shortcut operations, n8n writes the SQL), Select (basic read). Parameterised query example: SELECT * FROM users WHERE email = $1 — pass the value via 'Query Parameters'. Never inline expression results directly into SQL → SQL injection risk.

Webhook
PostgreSQL (Select)
IF
PostgreSQL (Update)

Insert, Update, Delete and Upsert

CRUD in n8n: Insert adds rows (single or batch — multiple items go in as one batch insert). Update modifies rows by a WHERE clause. Delete removes them. The real star is Upsert: 'if the record exists update it, otherwise insert' — one node to check and write by email or any key. Behind the scenes it's the Postgres ON CONFLICT (column) DO UPDATE pattern; n8n builds it for you.

MongoDB: document-oriented data

MongoDB is a non-relational document store — the n8n node works directly with JSON. Operations: Find (query object, e.g. { status: 'active', tier: { $gte: 2 } }), Insert (item.json becomes the document), Update (filter + update object), Delete. Indexes matter: indexing common query fields makes a dramatic difference. For analytics there is Execute Aggregation operation for full aggregation pipelines.

Airtable: tables + views

Airtable is the most popular no-code store paired with n8n. Pick Base and Table; Operations: List (fetch records, narrow by view + filter), Get (single), Append (new record — field name mapping matters), Update (by record id), Delete. View support is strong — prepare a filtered set ('Hot Leads') in Airtable and let n8n pull that view, keeping filter logic in Airtable. Rate limit is 5 req/s — pair Loop + Wait.

Notion: databases and pages

The Notion API gives full database/page control. Operations: Database — Query (filter + sort), Get; Database Page — Create (new row), Update, Archive. The critical concept: Notion's 'page property' types (Title, Rich Text, Number, Select, Multi-Select, Date, Relation, Formula) — each has a different payload format. Verify the property types once in Notion before creating pages; the n8n property picker then guides you to the right shape.

Sensitive data and masking

Not everything coming out of the DB has to go out. Execution logs are visible to n8n itself and to admins — mask PII, card data and phone numbers. Pattern: pass the Postgres output through a Set node and overwrite sensitive fields (e.g. masking expression like {{ $json.email.replace(/(.{2}).*(@.*)/, '$1***$2') }}). Writing raw PII into logs or sending full payloads to Slack is the most common source of GDPR/KVKK violations.

This chapter's workflow (n8n editor view)

Webhook
PostgreSQL
IF
Set