Skip to content

Databases

MongoDB Database Management in VS Code

DBCode is a MongoDB extension for VS Code: browse collections, edit documents in a JSON editor that respects BSON types, run queries, and subscribe to change streams without leaving your editor. Install DBCode to get started, or read the MongoDB in VS Code how-to guide.

MongoDB is a leading document-oriented NoSQL database that provides high performance, scalability, and flexibility for modern applications. Key advantages include:

  • Schema flexibility: Store documents with varying structures in the same collection
  • Rich query language: Powerful query capabilities including aggregation pipelines
  • Horizontal scalability: Easily distribute data across multiple servers with sharding
  • High availability: Built-in replication and automated failover
  • Multi-model capabilities: Work with documents, time series, geospatial data, and graphs

MongoDB excels in handling large volumes of unstructured and semi-structured data, making it ideal for content management systems, mobile applications, IoT, and real-time analytics.

DBCode supports MongoDB’s authentication mechanisms, selectable under the connection’s driver settings:

  • Default / SCRAM-SHA-1 / SCRAM-SHA-256: Username and password (SCRAM is MongoDB’s default challenge-response auth)
  • MONGODB-X509: Certificate-based authentication using a client certificate
  • PLAIN (LDAP): Delegate authentication to an external LDAP service
  • GSSAPI (Kerberos): Single sign-on with a Kerberos ticket, no password required. Works on Windows (via SSPI), macOS, and Linux. On macOS and Linux you first obtain a ticket for your principal (for example with kinit user@REALM), then enter that principal as the username. Requires a Kerberos-enabled MongoDB deployment (MongoDB Enterprise).

To connect to MongoDB in DBCode:

  1. Open the DBCode Extension: Launch Visual Studio Code and open the DBCode extension.
  2. Add a New Connection: Click on the “Add Connection” icon.
  3. Complete connection form: Select MongoDB as the database type and enter:
    • Connection string URI or individual connection parameters
    • Authentication mechanism and credentials
    • SSL/TLS settings (if required)
    • Additional connection options
  4. Connect: Click save to establish your connection.
  5. Start Managing Your Data: Explore databases, collections, and documents.

For detailed instructions on connecting to MongoDB, refer to the Connect article.

MongoDB Atlas connections use the connection string from the Atlas dashboard:

  1. Get the connection string: In Atlas, open your cluster, click Connect, and choose Drivers. Copy the mongodb+srv:// connection string.
  2. Add a New Connection: In DBCode, add a new MongoDB connection and paste the connection string, filling in your database user’s password.
  3. Connect: Click save to establish your connection.

DBCode fully supports mongodb+srv:// SRV connection strings, including TLS.

DBCode enhances your MongoDB development experience with:

  • JSON document editor: Visually edit and validate document structures
  • Schema analysis: Understand document structure variations in collections
  • BSON type support: Work with MongoDB-specific data types
  • Live Streaming: Subscribe to Change Streams on any collection to watch inserts, updates, and deletes in real time. Right-click a collection and select Subscribe, or run db.collectionName.watch() in the editor. Requires a replica set or sharded cluster

By using MongoDB with DBCode, you can efficiently develop and manage your document databases directly within Visual Studio Code.

Alongside the MongoDB shell, DBCode’s query editor also accepts plain SQL. Any cell that starts with SELECT, INSERT, UPDATE, or DELETE (case-insensitive; comments above it are fine) runs as SQL against the current collection; anything else still runs as a shell command, unchanged. See Query with SQL for how the translation works across databases.

SELECT name, email, status
FROM users
WHERE status = 'active' AND signupDate >= '2026-01-01'
ORDER BY signupDate DESC
LIMIT 20;
UPDATE users
SET status = 'inactive'
WHERE email = 'jane@example.com';

Supported: SELECT (columns, *, or COUNT(*)) with WHERE (comparisons, LIKE/ILIKE, IN, BETWEEN, IS [NOT] NULL, AND/OR), ORDER BY, and LIMIT/OFFSET; single-row INSERT, UPDATE, and DELETE. String literals are compared using each field’s introspected type, so date and other typed-field comparisons work as expected. Joins, GROUP BY, subqueries, functions, aliases, and parameters aren’t supported yet - each returns a clear error naming the unsupported construct instead of running silently, and queries can’t span multiple databases.

UPDATE/DELETE statements without a WHERE clause go through the same confirmation (or deny) rules as SQL connections.

StatementSupport
SELECT (columns or *)Yes
SELECT COUNT(*)Yes - can’t combine with ORDER BY or OFFSET
INSERTSingle row, column list required
UPDATE ... SETYes
DELETEYes
  • WHERE: =, !=, <>, >, >=, <, <=; LIKE (%text%, text%, %text, or plain text for an exact match); NOT LIKE (%text%); ILIKE (case-insensitive); IN (...); BETWEEN; IS NULL/IS NOT NULL; AND/OR with parentheses
  • Ordering and paging: ORDER BY runs server-side; LIMIT and OFFSET are both supported
  • Comments: --, //, and # are all recognized
  • String values compared against date fields use the collection’s introspected types, so a literal like '2026-01-01' compares correctly against a real date field
  • String values compared against _id automatically match MongoDB ObjectIds
  • Queries can’t reach another database (db.collection) - connect to that database instead

Not yet supported: joins, GROUP BY/HAVING, DISTINCT, subqueries, CTEs, expressions or functions in SELECT, aliases, parameters, and UNION - each returns a clear error naming the construct, as noted above.

For more information about MongoDB, check out MongoDB.