Connecting to the MongoDB database is a paid feature. Check Pricing Details to learn more. MongoDB is a document-oriented database management system belonging to non-relational databases (NoSQL). It aims to provide scalable high-performance data storage solutions for web applications. Unlike relational databases (SQL), MongoDB does not use SQL statements to operate on the database, but uses database commands (Database Commands) or simpler and more user-friendly methods of adding, deleting, querying and modifying data. Further reading: MongoDB Documentation.Connect to the database#
1.
When adding database operations, click Database Connetions
and select Manage Database Connection
.
2.
Click the "New" button in the upper right corner.
3.
Select MongoDB
database type, then fill in the corresponding connection information.
Apidog attaches importance to your data security. The database address, port, username, password, database name are only stored locally on the client and will not be synced to the cloud. Even within the same team, connection information for databases will not be synced between members. Each team member needs to manually set up the database connection.
Operate the database#
MongoDB stores document data in BSON format. In Apidog, you can directly use standard MongoDB query syntax—such as ISODate(...)
or ObjectId(...)
—to write query filters and update conditions, enabling more precise control over data types.For example, suppose your MongoDB database contains the following BSON document:{
_id: ObjectId('65486728456e79993a150f1c'),
name: "Apidog"
}
To query this document by _id
using Apidog, you can enter the following in the "Query Condition" section:{
"_id": "65486728456e79993a150f1c"
}
{
"_id": ObjectId('65486728456e79993a150f1c')
}
When you use a string representation of _id
that matches the ObjectId format, Apidog will automatically convert it to a BSON ObjectId for the query.Common operations#
For common CRUD operations, support via visual API operations. No need to write any JavaScript code, just specify the action in the "Operation Type", then specify the "Collection Name", and then write the corresponding content in JSON in "Query Conditions".For example, for the query operation mentioned above, you can view the queried document in the console after entering the command and enabling "Console Log".To support more advanced query requirements, you can also use BSON data type expressions in your query conditions, fully compatible with official MongoDB syntax.For example, the following query condition is valid:Supported BSON types include (but are not limited to):Type | Example Syntax | Description |
---|
Date | ISODate("2023-11-15T00:00:00.000+00:00") | Timestamp with millisecond precision |
ObjectId | ObjectId("507f1f77bcf86cd799439011") | Common type for MongoDB document IDs |
Timestamp | Timestamp(1601000000, 1) | Used for internal oplog operations |
Decimal128 | NumberDecimal("19.99") | High-precision decimal |
Int64 | NumberLong("9223372036854775807") | 64-bit integer |
Advanced commands#
If you need more advanced operations, you can also directly run database commands. In "Operation Type", select "Run Database Command" and then enter the database command in JSON format. Note that the database command does not refer to method calls like db.collection.findOne()
, but JSON data in a specific format.For example, to query the number of documents in the users collection, you can use the count
database command:After entering the command, you can view the result in the console.