MongoDB database exploration and querying. Use when you need to understand database structure, view existing data, check collection schemas, count documents, or run queries to investigate the database state. (project)
Use this skill when you need to explore the MongoDB database to understand data structure, verify existing records, or investigate database state.
Use mongosh or a MongoDB client to explore the database:
# Connect to MongoDB
mongosh mongodb://localhost:27017/freelancelyst
# Show all collections
show collections
# Count documents in a collection
db.users.countDocuments()
db.blogposts.countDocuments()
# View sample documents
db.users.find().limit(5).pretty()
db.blogposts.find().limit(5).pretty()
# Query with filters
db.blogposts.find({ status: "published" }).limit(10).pretty()
db.users.find({ roles: "admin" }).pretty()
# Aggregate examples
db.blogposts.aggregate([
{ $group: { _id: "$status", count: { $sum: 1 } } }
])
The database has the following collections:
Collection: users
{
_id: ObjectId,
name: string,
email: string,
password: string, // bcrypt hashed
roles: string[], // ['user'] or ['admin']
createdAt: Date,
updatedAt: Date
}
Collection: blogposts
{
_id: ObjectId,
slug: string, // unique
status: 'draft' | 'published' | 'archived',
publishedAt: Date | null,
coverImage: string | null,
owner: ObjectId, // ref: users
category: ObjectId | null, // ref: blogcategories
tags: ObjectId[], // refs: blogtags
translations: [
{ langCode: 'en' | 'fa', title: string, content: string, excerpt: string }
],
createdAt: Date,
updatedAt: Date
}
Collection: blogcategories
{
_id: ObjectId,
slug: string, // unique
translations: [
{ langCode: 'en' | 'fa', name: string }
],
createdAt: Date,
updatedAt: Date
}
Collection: blogtags
{
_id: ObjectId,
slug: string, // unique
translations: [
{ langCode: 'en' | 'fa', name: string }
],
createdAt: Date,
updatedAt: Date
}
Collection: projectapplications
{
_id: ObjectId,
title: string,
description: string,
budgetEstimate: string,
deadline: string,
clientEmail: string | null,
utm: object | null, // UTM tracking params
createdAt: Date,
updatedAt: Date
}
Collection: freelancerapplications
{
_id: ObjectId,
fullName: string,
email: string,
skillTags: string,
description: string,
utm: object | null, // UTM tracking params
createdAt: Date,
updatedAt: Date
}
db.blogposts.find({
"translations.langCode": "en"
}).pretty()
db.blogposts.aggregate([
{ $match: { status: "published" } },
{ $lookup: {
from: "blogcategories",
localField: "category",
foreignField: "_id",
as: "categoryData"
}},
{ $limit: 5 }
])
db.projectapplications.aggregate([
{ $group: {
_id: { $month: "$createdAt" },
count: { $sum: 1 }
}}
])
MONGODB_URI is set in your .env.local file