This guide helps you set up and import multiple MongoDB databases for the Great AI Hackathon project. The setup includes 5 separate databases with Malaysian government service data.
© 2025 Goodbye World team, for Great AI Hackathon Malaysia 2025 usage.
- MongoDB installed and running
- MongoDB command line tools (
mongoimport) available - Database connection access
databases/
├── accounts.json # Government service accounts database
├── idcards.json # Malaysian identity cards database
├── licenses.json # Malaysian driving license database
├── tnb-bills.json # TNB electricity bills database
└── transactions.json # Payment transactions database
chats/ # Chat messages database (user-specific collections)
├── (default) # Default collection for general chat
└── (userId) # Individual user chat collections (e.g., YYMMDD-XX-XXXX)
All JSON files contain structured data ready for MongoDB import. Some files use array format while others contain individual documents.
mongoimport --db databases --collection accounts --file databases/accounts.json --jsonArraymongoimport --db databases --collection idcards --file databases/idcards.json --jsonArraymongoimport --db databases --collection licenses --file databases/licenses.json --jsonArraymongoimport --db databases --collection tnb-bills --file databases/tnb-bills.json --jsonArraymongoimport --db databases --collection transactions --file databases/transactions.json --jsonArrayThe chats database is special - it contains user-specific collections:
# Create the chats database (will be created automatically when first collection is added)
# Each user will have their own collection named by userId
# Collections: chats.userId (e.g., chats.YYMMDD-XX-XXXX) and chats.(default)
# Example collections: "YYMMDD-XX-XXXX", "(default)"
mongoimport -db chats --collection (default) --file sample/chat-empty.jsonCreate a .env file based on .env.example to store your MongoDB connection details:
ATLAS_URI=mongodb+srv://<username>:<password>@<cluster>.mongodb.net
ATLAS_DB_NAME=databases
mongoimport --db databases --collection accounts --file databases\accounts.json --jsonArray
mongoimport --db databases --collection idcards --file databases\idcards.json --jsonArray
mongoimport --db databases --collection licenses --file databases\licenses.json --jsonArray
mongoimport --db databases --collection tnb-bills --file databases\tnb-bills.json --jsonArray
mongoimport --db databases --collection transactions --file databases\transactions.json --jsonArray
mongoimport -db chats --collection (default) --file sample/chat-empty.json# Set your Atlas URI as environment variable (Windows CMD)
SET ATLAS_URI=mongodb+srv://<username>:<password>@<cluster>.mongodb.net
SET ATLAS_DB_NAME=databases
# Import all databases using environment variable
mongoimport --uri "%ATLAS_URI%" --db "%ATLAS_DB_NAME%" --collection accounts --file databases\accounts.json --jsonArray
mongoimport --uri "%ATLAS_URI%" --db "%ATLAS_DB_NAME%" --collection idcards --file databases\idcards.json --jsonArray
mongoimport --uri "%ATLAS_URI%" --db "%ATLAS_DB_NAME%" --collection licenses --file databases\licenses.json --jsonArray
mongoimport --uri "%ATLAS_URI%" --db "%ATLAS_DB_NAME%" --collection tnb-bills --file databases\tnb-bills.json --jsonArray
mongoimport --uri "%ATLAS_URI%" --db "%ATLAS_DB_NAME%" --collection transactions --file databases\transactions.json --jsonArray
mongoimport --uri "%ATLAS_URI%" --db chats --collection (default) --file sample/chat-empty.jsonmongoimport --uri "mongodb+srv://username:password@cluster.mongodb.net" --db "%ATLAS_DB_NAME%" --collection accounts --file databases/accounts.json --jsonArray
mongoimport --uri "mongodb+srv://username:password@cluster.mongodb.net" --db "%ATLAS_DB_NAME%" --collection idcards --file databases/idcards.json --jsonArray
mongoimport --uri "mongodb+srv://username:password@cluster.mongodb.net" --db "%ATLAS_DB_NAME%" --collection licenses --file databases/licenses.json --jsonArray
mongoimport --uri "mongodb+srv://username:password@cluster.mongodb.net" --db "%ATLAS_DB_NAME%" --collection tnb-bills --file databases/tnb-bills.json --jsonArray
mongoimport --uri "mongodb+srv://username:password@cluster.mongodb.net" --db "%ATLAS_DB_NAME%" --collection transactions --file databases/transactions.json --jsonArray
mongoimport --uri "mongodb+srv://username:password@cluster.mongodb.net" --db chats --collection (default) --file sample/chat-empty.json
import-allclean-allcreate-unique-index| Parameter | Description | Example |
|---|---|---|
--host |
MongoDB host and port | localhost:27017 |
--uri |
Complete connection string | mongodb://user:pass@host:port/db |
--username |
Authentication username | myuser |
--password |
Authentication password | mypassword |
--authenticationDatabase |
Auth database | admin |
--ssl |
Enable SSL/TLS | --ssl |
--db |
Target database name | accounts |
--collection |
Target collection name | accounts |
--file |
Input JSON file path | databases/accounts.json |
--jsonArray |
Import JSON array format | --jsonArray |
# Test MongoDB connection
mongo --eval "db.runCommand('ping')"
# Test with authentication
mongo --username your_username --password your_password --authenticationDatabase admin --eval "db.runCommand('ping')"
# Test Atlas connection
mongo "mongodb+srv://username:password@cluster.mongodb.net" --eval "db.runCommand('ping')"tnb-bills.bill.akaun.no_invoismatchestransactions.metadata.tnbInvoiceIdtnb-bills.pembayaran.rujukanmatchestransactions._idtransactions.billplz.billIdmatchesaccounts.billplz_collection_id
- Government service accounts store beneficiary information
- Transactions reference service types (LICENSE_RENEWAL, PAY_TNB_BILL)
idcards.userIdmatcheslicenses.userId
- License renewals generate transactions with serviceType "LICENSE_RENEWAL"
- License numbers stored in transaction metadata
- User-specific collections store chat history
- Collections named by userId (e.g.,
YYMMDD-XX-XXXX) - Default collection contains conversation messages
// Connect to accounts database
use accounts
// Find all active government service accounts
db.accounts.find({"active": true})
// Find TNB service accounts
db.accounts.find({"service": "TNB"})// Connect to idcards database
use idcards
// Find all valid ID cards
db.idcards.find({"status": "valid"})
// Find ID cards by userId
db.idcards.find({"userId": "YYMMDD-XX-XXXX"})// Connect to licenses database
use licenses
// Find valid licenses
db.licenses.find({"status": "valid"})
// Find licenses expiring soon
db.licenses.find({"valid_to": {$lt: "2026-01-01"}})// Connect to tnb-bills database
use tnb-bills
// Find paid bills
db['tnb-bills'].find({"status": "paid"})
// Find overdue bills
db['tnb-bills'].find({"status": "overdue"})
// Find residential tariff bills
db['tnb-bills'].find({"bill.tarif.jenis": "A: Kediaman"})// Connect to transactions database
use transactions
// Find all paid transactions
db.transactions.find({"status": "paid"})
// Find TNB bill payments
db.transactions.find({"serviceType": "PAY_TNB_BILL"})
// Find license renewals
db.transactions.find({"serviceType": "LICENSE_RENEWAL"})// Connect to chats database
use chats
// List all user collections (user chat histories)
show collections
// Access specific user's chat history
db['YYMMDD-XX-XXXX'].find()After import, verify database and collection counts:
// Check all databases
show dbs
// Verify each database
use accounts
db.accounts.countDocuments()
use idcards
db.idcards.countDocuments()
use licenses
db.licenses.countDocuments()
use tnb-bills
db['tnb-bills'].countDocuments() // Should return 5 (1 original + 4 new)
use transactions
db.transactions.countDocuments() // Should return 4 (2 original + 2 new)
use chats
show collections // Will show user-specific collections{
agency: "String", // JPJ, TNB, etc.
billplz_collection_id: "String"
}{
full_name: "String", // Full name in ID card
userId: "String", // Malaysian IC format, e.g., YYMMDD-XX-XXXX
gender: "String", // Male, Female, etc.
address: "String", // Address in ID card
}{
full_name: "String", // Full name in license, e.g. JOHN DOE
userId: "String", // Malaysian IC format, e.g., YYMMDD-XX-XXXX
dob: "String", // YYYY-MM-DD
nationality: "String", // MALAYSIA, etc.
license_number: "String", // Malaysian license format, e.g., 0107011 abc123Xy
license_classes: ["String"], // D, DA, B2, etc.
valid_from: "String",
valid_to: "String",
address: "String",
status: "String" // valid, expired, suspended
}{
bill: {
akaun: {
no_akaun: "String", // TNB account number
no_kontrak: "String", // Contract number
deposit: Number, // Deposit amount
no_invois: "String", // Invoice number
name: "String",
address: "String"
},
meta: {
bil_semasa: Object, // Current bill details
butiran: Object, // Bill breakdown
bil_terdahulu: Object, // Previous bill
bayaran_akhir: Object // Last payment
jenis_bacaan: "String" // Reading type
},
tarif: {
tempoh: Object, // Tariff period
jenis: "String", // A: Kediaman (Residential)
faktor_prorata: Number, // Tariff factor
blok: [Object], // Tariff blocks
jumlah_kWh: Number,
jumlah_amaun: Number
},
caj: Object, // Charges breakdown
meter: Object // Meter readings
},
status: "String", // paid, unpaid, overdue
pembayaran: { // Payment details (if paid)
jumlah: Number,
tarikh_bayar: "ISO Date",
kaedah: "String", // MyGovHub
rujukan: "String" // Transaction reference
}
}{
_id: "String", // Unique transaction ID
userId: "String", // Malaysian IC format
serviceType: "String", // LICENSE_RENEWAL, PAY_TNB_BILL
description: "String",
amount: Number, // Amount in MYR
currency: "String", // MYR
status: "String", // paid, pending, failed
createdAt: "ISO Date",
updatedAt: "ISO Date",
billplz: { // Payment gateway details
billId: "String", // bill_xyz123 (TNB), bill_xyz789 (JPJ)
url: "String",
paidAt: "ISO Date",
transactionId: "String",
webhookPayload: Object
},
metadata: {
sessionId: "String",
// Service-specific metadata
tnbAccountId: "String", // For TNB bills
tnbInvoiceId: "String",
renewalYears: Number, // For license renewals
licenseNumber: "String"
}
}// Collection name: userId (e.g., "YYMMDD-XX-XXXX") or "default"
{
sessionId: "String", // Unique session identifier
createdAt: "ISO Date", // Session creation timestamp
messages: [ // Array of chat messages
{
messageId: "String", // Unique message identifier
message: "String", // Message content
timestamp: "ISO Date", // Message timestamp
type: "String", // user, assistant
intent: "String", // Optional: renew_license, document_processing, etc.
attachment: [ // Optional: file attachments
{
url: "String", // File URL
type: "String", // MIME type (image/jpeg, etc.)
name: "String" // Original filename
}
]
}
],
status: "String", // active, completed, archived
topic: "String", // Main conversation topic
context: { // User context information
full_name: "String", // User's full name
userId: "String", // Malaysian IC format (YYMMDD-XX-XXXX)
gender: "String", // LELAKI, PE#PUAN
address: "String" // User's address
},
ekyc: { // eKYC verification data (if applicable)
tnb_account_no: ["String"], // Array of TNB account numbers (if any)
iwk_account_no: ["String"] // Array of IWK account numbers (if any)
}
}-
File Path Issues (Windows)
- Use backslashes
\for Windows paths - Ensure you're in the correct directory
- Use backslashes
-
JSON Array Import
- Use
--jsonArrayflag for array-formatted files - Each database file may have different formats
- Use
-
Database vs Collection Confusion
- This setup uses separate databases, not collections
- Each database contains its own collections
-
Chat Database Collections
- Chat collections are created dynamically per user
- Collection names follow userId format
# Check MongoDB connection
mongo --eval "db.runCommand('ping')"
# List all databases
mongo --eval "show dbs"
# Check specific database collections
mongo accounts --eval "show collections"
mongo idcards --eval "show collections"
mongo licenses --eval "show collections"
mongo tnb-bills --eval "show collections"
mongo transactions --eval "show collections"
mongo chats --eval "show collections"- Database Count: 5 separate databases
- Data Type: Malaysian Government Services (TNB, JPJ, etc.)
- Currency: Malaysian Ringgit (MYR)
- Date Format: ISO 8601 where applicable
- Special Database: Chats uses dynamic user-based collections
- Payment Gateway: Billplz integration with specific bill IDs
- Service Types: LICENSE_RENEWAL (RM30/year), PAY_TNB_BILL (variable amounts)
Project: Great AI Hackathon
Total Databases: 5 (accounts, licenses, tnb-bills, transactions, chats)
Data Source: Malaysian Government Services
Last Updated: October 2025