LogoLogo
  • Preen
  • Getting Started
    • Installation
    • Hello World
      • Configuring Sources
      • Creating Models
  • Concepts
    • Overview
    • Sources
    • Models
    • Validation
  • Documentation
    • Config
      • Sources
      • Models
    • Integrations
      • Databases
        • Postgres
        • MySQL
        • MongoDB
      • Cloud Blob Storage
        • Amazon S3
      • File Formats
        • CSV
Powered by GitBook
On this page
  • Example Preen Source Configuration
  • Mongo Database Models
  • Code References
  1. Documentation
  2. Integrations
  3. Databases

MongoDB

how to configure preen to connect to MongoDB databases.

PreviousMySQLNextCloud Blob Storage

Last updated 7 months ago

Preen can connect to MongoDB databases. Our current implementation uses the Go library to connect to databases.

Example Preen Source Configuration

# FILENAME: ~/.preen/sources.yaml
sources:
  - name: mongo-example
    engine: mongodb
    connection:
      host: localhost
      port: 27117
      database: preendb
      username: ${MONGODB_USERNAME}
      password: ${MONGODB_PASSWORD}
      auth_source: admin

Mongo Database Models

MongoDB models are defined as a YAML file that contains a MongoDB document filter. This filter is used to match documents in the database and return the data that matches the filter. The documents are written to DuckDB as a JSON column for local querying using the native .

# FILENAME: ~/.preen/models/users.yaml
name: users-mongodb
type: mongodb
collection: users # The name of the collection to query.
query: |
    {
      "login_attempts": {
        "$gt": 1
      },
      "account_status": {
        "$in": ["inactive", "suspended"]
      }
    }

Code References

mongo
JSON querying capabilities of DuckDB
mongo.go