Using databases
This documentation outlines the key components for managing MongoDB, PostgreSQL, SQL, and MySQL within JDoodle IDE.
JDoodle’s preconfigured setup lets you focus on writing and testing queries without additional configuration. You’ll need:
- A JDoodle account. Sign up here if you don’t already have one.
- Basic knowledge of databases.
Components in databases
Here are the essential components: Root, Query Logs, Database Info, and Console.
Root
The root directory is the foundational hub for all your databases and their structures. Here, you can efficiently create, organize, and manage your databases, schemas, collections, tables, and other databases. Whether you’re working with collections in MongoDB or schemas and tables in SQL-based databases like PostgreSQL and MySQL, the root directory provides a centralized location to handle your database entities.
Query Logs
All queries executed within the IDE are automatically logged, providing a comprehensive record of your database interactions. Access the Query Logs to review, debug, and optimize your database operations. The logs offer detailed information about each query’s execution time, performance metrics, and any errors encountered, helping you maintain and enhance the efficiency of your database activities.
Database Info
The Database Info section offers comprehensive details about your databases, including:
- Database Names: A list of all available databases within your environment.
- Object Counts: Number of collections (for MongoDB) or tables, views, and other objects (for SQL-based databases) within each database.
- Storage Size: Disk space utilized by each database, providing insights into storage management.
- Index Information: Details about indexes applied to collections or tables, essential for query optimization and performance.
Console
The Console provides a powerful interface to execute database commands directly within the IDE. Whether you need to perform CRUD operations, manage indexes, run SQL scripts, or execute aggregation pipelines, the Console supports all necessary operations. It allows you to interact with your databases using MongoDB Shell commands, SQL statements, or other relevant query languages, facilitating efficient and direct database management.
Writing code
This section provides basic examples of writing code to interact with each database type—MongoDB , PostgreSQL , SQL , and MySQL
MongoDB
// Insert a new document
db.mycollection.insertOne({ name: 'Jane Doe', age: 30 });
// Find a document
const user = db.mycollection.findOne({ name: 'Jane Doe' });
console.log(user);
// Update a document
db.mycollection.updateOne({ name: 'Jane Doe' }, { $set: { age: 31 } });
// Delete a document
db.mycollection.deleteOne({ name: 'Jane Doe' });
PostgreSQL
-- Create a new table
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name VARCHAR(100),
email VARCHAR(100)
);
-- Insert a new user
INSERT INTO users (name, email) VALUES ('Jane Doe', 'jane@example.com');
-- Select a user
SELECT * FROM users WHERE name = 'Jane Doe';
-- Update a user
UPDATE users SET email = 'jane.doe@example.com' WHERE name = 'Jane Doe';
-- Delete a user
DELETE FROM users WHERE name = 'Jane Doe';
SQL
-- Create a new table
CREATE TABLE products (
id INT PRIMARY KEY,
name VARCHAR(100),
price DECIMAL(10, 2)
);
-- Insert a new product
INSERT INTO products (id, name, price) VALUES (1, 'Laptop', 999.99);
-- Select a product
SELECT * FROM products WHERE name = 'Laptop';
-- Update a product
UPDATE products SET price = 899.99 WHERE name = 'Laptop';
-- Delete a product
DELETE FROM products WHERE name = 'Laptop';
MySQL
-- Create a new table
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100),
email VARCHAR(100)
);
-- Insert a new record
INSERT INTO users (name, email) VALUES ('Jane Doe', 'jane@example.com');
-- Select a record
SELECT id, name, email FROM users WHERE name = 'Jane Doe';
-- Update a record
UPDATE users SET email = 'jane.doe@example.com' WHERE name = 'Jane Doe';
-- Delete a record
DELETE FROM users WHERE name = 'Jane Doe';
Troubleshooting & help
- Verify package names and reinstall if necessary.
- Check the console for errors, ensure your code follows proper syntax, and confirm all components are correctly imported.
- Ensure HTML elements match your code targets and that components are properly structured.
If you have more issues or questions, you can ask them in the JDoodle community.