-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschemas.py
More file actions
61 lines (57 loc) · 1.6 KB
/
schemas.py
File metadata and controls
61 lines (57 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Sample schemas for MongoDB collections
# User Schema - Basic user information
user_schema = {
"name": str, # User's full name
"email": str, # Unique email address
"age": int, # User's age
"created_at": "datetime", # Account creation timestamp
"address": { # Nested document example
"street": str,
"city": str,
"country": str
},
"interests": [str] # Array example
}
# Product Schema - E-commerce example
product_schema = {
"name": str,
"price": float,
"description": str,
"category": str,
"in_stock": bool,
"tags": [str],
"supplier": {
"name": str,
"contact": str
},
"reviews": [{ # Array of nested documents
"user_id": "ObjectId", # Reference to User collection
"rating": int,
"comment": str,
"date": "datetime"
}]
}
# Order Schema - Demonstrates relationships
order_schema = {
"user_id": "ObjectId", # Reference to User collection
"status": str,
"items": [{
"product_id": "ObjectId", # Reference to Product collection
"quantity": int,
"price": float
}],
"total_amount": float,
"shipping_address": {
"street": str,
"city": str,
"country": str
},
"order_date": "datetime",
"payment_status": str
}
"""
Note: These are just schema definitions for reference.
In MongoDB, schemas are flexible and not strictly enforced like in SQL databases.
Types shown here are Python types, in MongoDB they would be BSON types.
ObjectId references are shown as strings here but would be actual ObjectId in MongoDB.
"""