Skip to main content

MongoDB

info

Connecting to the MongoDB database is a paid feature. Check Pricing Details to know 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. Click "Processors Operation" in the API and select "Database Operations".

  1. Click "Manage Database Connection" in the dropdown box under "Database Connection", then click the "New" button in the upper right corner.

  1. Select MongoDB database type, then fill in the corresponding connection information.

tip

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 data in BSON document format. For convenience of most user's usage habits, when modifying MongoDB databases in Apidog, submit JSON format files. The system will automatically map each field to the corresponding BSON data type based on the actual content of the JSON.

Among them, the _id field is relatively special. According to MongoDB specifications, each document must have an _id field as the primary key, and the default data type of this field is ObjectId rather than String.

If you need to declare an _id field of type ObjectId, you can use the conventional string format. If the string content conforms to the ObjectId format, Apidog will automatically map it to the ObjectId type in BSON.

Assume there is such a BSON document in MongoDB now:

{
_id: ObjectId('6569a36afcf5ee79c08d2f94'),
name: "Apidog"
}

So when using Apidog to query the document via _id, the JSON value that needs to be entered in the "Query Conditions" is:

{
"_id": "6569a36afcf5ee79c08d2f94"
}

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".

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:

{
"count": "users"
}

After entering the command, you can view the result in the console.