-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmongo-init.js
More file actions
70 lines (64 loc) · 1.77 KB
/
Copy pathmongo-init.js
File metadata and controls
70 lines (64 loc) · 1.77 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
62
63
64
65
66
67
68
69
70
// MongoDB Initialization Script for NASDAQ Stock Agent
// This script creates a dedicated user for the application database
db = db.getSiblingDB('nasdaq_stock_agent');
// Create application user with read/write permissions
db.createUser({
user: process.env.MONGO_USERNAME || 'nasdaq_user',
pwd: process.env.MONGO_PASSWORD || 'change_this_secure_user_password',
roles: [
{
role: 'readWrite',
db: 'nasdaq_stock_agent'
}
]
});
// Create collections with validation
db.createCollection('stock_analyses', {
validator: {
$jsonSchema: {
bsonType: 'object',
required: ['symbol', 'timestamp'],
properties: {
symbol: {
bsonType: 'string',
description: 'Stock ticker symbol - required'
},
timestamp: {
bsonType: 'date',
description: 'Analysis timestamp - required'
},
analysis: {
bsonType: 'object',
description: 'Analysis results'
}
}
}
}
});
db.createCollection('cache', {
validator: {
$jsonSchema: {
bsonType: 'object',
required: ['key', 'value', 'expires_at'],
properties: {
key: {
bsonType: 'string',
description: 'Cache key - required'
},
value: {
description: 'Cached value - required'
},
expires_at: {
bsonType: 'date',
description: 'Expiration timestamp - required'
}
}
}
}
});
// Create indexes for better performance
db.stock_analyses.createIndex({ symbol: 1, timestamp: -1 });
db.stock_analyses.createIndex({ timestamp: -1 });
db.cache.createIndex({ key: 1 }, { unique: true });
db.cache.createIndex({ expires_at: 1 }, { expireAfterSeconds: 0 });
print('MongoDB initialization completed successfully');