원클릭으로
builderx-api-mongodb
Patterns for using MongoDB driver and dynamic collections in BuilderX API
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Patterns for using MongoDB driver and dynamic collections in BuilderX API
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Phoenix Channel patterns in landing_page_backend — real-time collaboration, WebSocket topics, broadcasting, and channel structure.
Guide to Context module patterns in landing_page_backend — Ecto queries, dynamic query building, Ecto.Multi, and Outbox messaging.
Guide to Phoenix Controller structure in landing_page_backend using FallbackController, tuple responses, and permission plugs.
Patterns for creating Oban background workers in landing_page_backend — queue configuration, job arguments, retry strategies, and dynamic query processing.
Custom Plug middleware patterns in landing_page_backend — authentication (JWT/Passport), authorization, permission checking, and rate limiting.
Guidelines for creating Ecto Schemas in landing_page_backend, including binary UUID primary keys, virtual fields, custom json/1 function, and multiple changeset patterns.
| name | builderx_api-mongodb |
| description | Patterns for using MongoDB driver and dynamic collections in BuilderX API |
| metadata | {"author":"Vũ Lưu","version":"2026.03.25","source":"Source code builderx_api"} |
The builderx_api project integrates MongoDB via the mongodb_driver alongside its primary Postgres (Citus) database. This is used extensively for the Dynamic Database Collections feature in BuilderxApi.DBCollections.DBCollections (lib/builderx_api/db_collections/db_collections.ex).
In this pattern, metadata about the data models (schema) is stored in Postgres (DBCollection), but the actual records are physically stored in MongoDB (MongoRepo) using a single records table separated by table_name and site_id.
You should generally not interact with MongoRepo directly unless you are inside the builderx_api/db_collections/... scope.
Instead, use DBCollections:
filters = %{"slug" => "my-record"}
# conn must have assigns for customer, account, or is_check_record_creator as required
DBCollections.exists_record(table_name, filters, db_collection_struct, conn)
# => {:ok, true | false}
Retrieves customized results based on dynamic schemas.
select = %{"id" => 1, "name" => 1}
filters = %{"status" => "active"}
limit = 10
skip = 0
sort = %{"inserted_at" => -1} # Use 1 for ASC, -1 for DESC
populate = [] # Populate relations if any references are configured
params = %{"site_id" => "site_uuid"}
DBCollections.query_record(
table_name,
select,
filters,
sort,
limit,
skip,
populate,
params,
conn
)
# => List of normalized maps
# attrs is a list of map: [%{"field_name" => "name", "field_value" => "Record 1"}]
# Note that we use a custom key format for dynamic mapping.
{:ok, inserted_record} = DBCollections.insert_record(table_name, attrs, params, conn)
MongoRepo directlyThe BuilderxApi.MongoRepo is an abstraction over :mongo (the mongodb_driver pool).
For some administrative actions, it is called directly:
alias BuilderxApi.MongoRepo
table = "records"
# Find
records = MongoRepo.find(table, %{"site_id" => site_id, "table_name" => "users"})
# Find one
record = MongoRepo.find_one(table, %{"_id" => id})
# Update Many
MongoRepo.update_many(
table,
%{"site_id" => site_id, "table_name" => "users"},
%{"$unset" => %{"webcmscol_removed_field" => ""}}
)
# Insert Many
MongoRepo.insert_many(table, list_of_maps)
# Delete Many
MongoRepo.delete_many(table, %{"site_id" => site_id, "table_name" => "users"})
webcmscol_: The system prepends webcmscol_ to column names stored in MongoDB to prevent clashes with system variables like _id, site_id, table_name. You will see operations map/unmap this prefix (DBUtils.sanitize_column_name/1).db_collection_records::{site_id}.records collection but are differentiated by standard root fields: "site_id" and "table_name".