curl --request POST \
--url https://api.example.com/{collection} \
--header 'Authorization: <authorization>' \
--header 'Content-Type: application/json' \
--data '
{
"field_name": "<any>"
}
'{
"_id": "<string>",
"created_at": "<string>",
"updated_at": "<string>",
"created_by": "<string>",
"...": "<any>"
}Create a new document in a collection with automatic field population and validation
curl --request POST \
--url https://api.example.com/{collection} \
--header 'Authorization: <authorization>' \
--header 'Content-Type: application/json' \
--data '
{
"field_name": "<any>"
}
'{
"_id": "<string>",
"created_at": "<string>",
"updated_at": "<string>",
"created_by": "<string>",
"...": "<any>"
}Documentation Index
Fetch the complete documentation index at: https://mintlify.com/KTS-o7/permission-mongo/llms.txt
Use this file to discover all available pages before exploring further.
created_at, updated_at, created_by fieldscreated_at (timestamp)updated_at (timestamp)created_by (user ID from auth context)curl -X POST https://api.example.com/users \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "John Doe",
"email": "john@example.com",
"role": "member"
}'
{
"_id": "507f1f77bcf86cd799439011",
"name": "John Doe",
"email": "john@example.com",
"role": "member",
"created_at": "2024-03-15T10:30:00Z",
"updated_at": "2024-03-15T10:30:00Z",
"created_by": "user_123",
"company_id": "company_456"
}
insertOne operation:
result, err := collection.InsertOne(ctx, doc)
if err != nil {
return err
}
id := result.InsertedID
created_by, created_at, updated_at (handlers_crud.go:108-111)company_id) from auth context (handlers_crud.go:114)now := time.Now().UTC()
doc["created_by"] = authCtx.UserID
doc["created_at"] = now
doc["updated_at"] = now
// Set tenant/company_id from auth if configured
if collConfig.Access.TenantField != "" {
doc[collConfig.Access.TenantField] = authCtx.TenantID
}
if collConfig.Access.OwnerField != "" {
doc[collConfig.Access.OwnerField] = authCtx.UserID
}
{
"error": "Validation failed",
"code": "schema_validation",
"details": {
"validation_errors": [
{
"field": "email",
"code": "invalid_format",
"message": "Invalid email format"
}
]
}
}
{
"error": "Authentication required"
}
{
"error": "You don't have permission to perform this action",
"code": "forbidden",
"details": {
"action": "create",
"collection": "users"
}
}
{
"error": "Collection not found",
"code": "collection_not_found",
"details": {
"collection": "invalid_collection"
}
}
{
"error": "Failed to create document",
"code": "internal_error",
"details": {
"error": "database connection failed"
}
}
function preCreate(event) {
// event.after contains the document to be created
// Modify or validate the document
event.after.slug = event.after.name.toLowerCase().replace(/\s+/g, '-');
return event;
}
function postCreate(event) {
// event.after contains the created document with _id
// Trigger side effects like notifications
sendWelcomeEmail(event.after.email);
}