The DocumentDB for VS Code extension is a powerful, open-source GUI that helps you browse, manage, and query DocumentDB and MongoDB databases across any cloud, hybrid, or local environment.
DocumentDB for VS Code provides a developer-centric experience with minimal setup, offering universal support for both DocumentDB and MongoDB databases. Whether you're working with cloud-based, hybrid cloud, on-premises, or local instances, this extension provides the tools you need for efficient database management.
Use the command palette:
ext install ms-azuretools.vscode-documentdbStart a local DocumentDB instance using Docker:
docker pull ghcr.io/documentdb/documentdb/documentdb-local:latest
docker tag ghcr.io/documentdb/documentdb/documentdb-local:latest documentdb
docker run -dt -p 10260:10260 --name documentdb-container documentdb --username admin --password password123
docker image rm -f ghcr.io/documentdb/documentdb/documentdb-local:latestNote: We're using port 10260 to avoid conflicts with other local database services. You can use port 27017 (the standard MongoDB port) if you prefer.
Connect to DocumentDB using the VS Code extension:
mongodb://admin:password123@localhost:10260/?tls=true&tlsAllowInvalidCertificates=true&authMechanism=SCRAM-SHA-256// Create a new database
// Right-click in the database explorer and select "Create Database"
// Create a new collection
// Right-click on a database and select "Create Collection"
// Create a new document
// Right-click on a collection and select "Create Document"// Find all documents
db.collection.find({})
// Find documents with filters
db.collection.find({ status: "active" })
// Find documents with complex filters
db.collection.find({
age: { $gte: 18 },
status: { $in: ["active", "pending"] }
})// Basic aggregation
db.collection.aggregate([
{ $match: { status: "active" } },
{ $group: { _id: "$category", count: { $sum: 1 } } },
{ $sort: { count: -1 } }
])
// Complex aggregation with multiple stages
db.sales.aggregate([
{ $match: { date: { $gte: new Date("2024-01-01") } } },
{ $lookup: { from: "products", localField: "productId", foreignField: "_id", as: "product" } },
{ $unwind: "$product" },
{ $group: { _id: "$product.category", totalSales: { $sum: "$amount" } } }
])// Create a new document
{
"name": "John Doe",
"email": "john@example.com",
"age": 30,
"created_at": new Date(2024-11-16),
"tags": ["user", "active"]
}// Create a new scrapbook file (.mongo)
// This allows you to save and reuse queries
// Example scrapbook content
db.users.find({ status: "active" }).limit(10)
// You can include multiple queries
db.users.countDocuments({ status: "active" })
db.users.aggregate([
{ $match: { status: "active" } },
{ $group: { _id: "$department", count: { $sum: 1 } } }
])// View all indexes on a collection
db.collection.getIndexes()// Create a single field index
db.collection.createIndex({ "email": 1 })
// Create a compound index
db.collection.createIndex({ "lastName": 1, "firstName": 1 })
// Create a unique index
db.collection.createIndex({ "email": 1 }, { unique: true })
// Create a geospatial index
db.collection.createIndex({ "location": "2dsphere" })// Analyze query performance
db.collection.find({ email: "user@example.com" }).explain("executionStats")// Get database statistics
db.stats()
// Get collection statistics
db.collection.stats()
// Get server status
db.runCommand({ serverStatus: 1 })The VS Code extension is particularly useful for migrating from MongoDB to DocumentDB:
.limit() for large result sets