Skip to content

Commit 4412b00

Browse files
authored
Update mongo-init.js
1 parent 7a25850 commit 4412b00

1 file changed

Lines changed: 28 additions & 14 deletions

File tree

mongo-init.js

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
1+
js
12

2-
---
3+
db = db.getSiblingDB("fullstack_app");
34

4-
## **6️⃣ `mongo-init.js` (sample)**
5+
// Seed users
6+
if (db.users.countDocuments() === 0) {
7+
db.users.insertMany([
8+
{
9+
name: "Admin User",
10+
email: "admin@example.com",
11+
password: "admin123", // hash in production
12+
role: "admin"
13+
},
14+
{
15+
name: "Test User",
16+
email: "user@example.com",
17+
password: "user123",
18+
role: "user"
19+
}
20+
]);
21+
print("✅ Seeded users collection");
22+
}
523

6-
```js
7-
// mongo-init.js - Seed data for MongoDB
8-
db = db.getSiblingDB('fullstack_app');
24+
// Seed items
25+
if (db.items.countDocuments() === 0) {
26+
db.items.insertMany([
27+
{ title: "First Item", description: "This is a seeded item." },
28+
{ title: "Second Item", description: "Another example entry." }
29+
]);
30+
print("✅ Seeded items collection");
31+
}
932

10-
db.users.insertMany([
11-
{ username: "admin", password: "admin123", role: "admin" },
12-
{ username: "user1", password: "user123", role: "user" }
13-
]);
14-
15-
db.products.insertMany([
16-
{ name: "Widget", price: 9.99, stock: 100 },
17-
{ name: "Gadget", price: 19.99, stock: 50 }
18-
]);
1933

2034
print("✅ MongoDB seed complete");

0 commit comments

Comments
 (0)