curl --request GET \
--url https://api.example.com/{collection}/{id} \
--header 'Authorization: <authorization>'{
"_id": "<string>",
"created_at": "<string>",
"updated_at": "<string>",
"created_by": "<string>",
"...": "<any>"
}Retrieve a single document by its unique identifier
curl --request GET \
--url https://api.example.com/{collection}/{id} \
--header 'Authorization: <authorization>'{
"_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.
_id. The endpoint:
curl -X GET https://api.example.com/users/507f1f77bcf86cd799439011 \
-H "Authorization: Bearer YOUR_TOKEN"
curl -X GET https://api.example.com/products/SKU-12345 \
-H "Authorization: Bearer YOUR_TOKEN"
{
"_id": "507f1f77bcf86cd799439011",
"name": "John Doe",
"email": "j***@example.com",
"role": "admin",
"status": "active",
"department": "Engineering",
"created_at": "2024-03-15T10:30:00Z",
"updated_at": "2024-03-15T14:25:00Z",
"created_by": "user_123",
"company_id": "company_456"
}
email field is masked based on the user’s role permissions.
findOne operation:
// Convert string ID to ObjectID if applicable
var filter bson.M
objectID, err := primitive.ObjectIDFromHex(id)
if err == nil {
filter = bson.M{"_id": objectID}
} else {
filter = bson.M{"_id": id} // String ID
}
var doc bson.M
err = collection.FindOne(ctx, filter).Decode(&doc)
if err == mongo.ErrNoDocuments {
return ErrNotFound
}
func applyFieldPolicy(authCtx *auth.AuthContext, collection string, doc map[string]interface{}) {
// Get role policies
var denyFields []string
var allowFields []string
for _, role := range authCtx.Roles {
rolePolicy := h.policy.GetRolePolicy(collection, role)
if rolePolicy != nil && rolePolicy.Fields != nil {
denyFields = append(denyFields, rolePolicy.Fields.Deny...)
allowFields = append(allowFields, rolePolicy.Fields.Allow...)
}
}
// If allow list is specified, only keep those fields
if len(allowFields) > 0 {
for field := range doc {
if !contains(allowFields, field) && field != "_id" {
delete(doc, field)
}
}
}
// Remove denied fields
for _, field := range denyFields {
delete(doc, field)
}
}
func applyFieldMasking(authCtx *auth.AuthContext, collection string, doc map[string]interface{}) {
// Get mask configuration from role policies
maskConfig := make(map[string]MaskType)
for _, role := range authCtx.Roles {
rolePolicy := h.policy.GetRolePolicy(collection, role)
if rolePolicy != nil && rolePolicy.Fields != nil {
for field, maskType := range rolePolicy.Fields.Mask {
maskConfig[field] = maskType
}
}
}
// Apply masks
for field, maskType := range maskConfig {
if val, ok := doc[field].(string); ok {
doc[field] = maskValue(val, maskType)
}
}
}
email: Shows first char and domain (e.g., j***@example.com)phone: Shows last 4 digits (e.g., ***-***-1234)partial: Shows first and last char (e.g., j***n)full: Replaces with ***# Example schema with computed field
fields:
first_name:
type: string
last_name:
type: string
full_name:
type: string
computed:
expression: "{{first_name}} {{last_name}}"
store: false # Not stored in DB, computed on read
if !h.canPerformAction(authCtx, collection, config.ActionRead, doc) {
return ErrForbidden
}
resource.created_by == user.idresource.company_id == user.tenant_idresource.department in user.departmentsresource.owner_id in user.subordinates{
"error": "Invalid document ID",
"code": "bad_request",
"details": {
"id": "invalid-id-format"
}
}
{
"error": "Authentication required"
}
{
"error": "You don't have permission to perform this action",
"code": "forbidden",
"details": {
"action": "read",
"collection": "users"
}
}
{
"error": "Document not found",
"code": "document_not_found",
"details": {
"collection": "users",
"id": "507f1f77bcf86cd799439011"
}
}
{
"error": "Failed to retrieve document",
"code": "internal_error",
"details": {
"error": "database connection failed"
}
}
# Get current user's profile
curl -X GET https://api.example.com/users/me \
-H "Authorization: Bearer YOUR_TOKEN"
# View order details
curl -X GET https://api.example.com/orders/ORD-12345 \
-H "Authorization: Bearer YOUR_TOKEN"
# Check task status
curl -X GET https://api.example.com/tasks/task_789 \
-H "Authorization: Bearer YOUR_TOKEN"