Supported Commands
Hint
This article is generated by AI translation.
jdbc-mongo parses raw Command instructions and converts them to underlying API calls. Below is the list of supported commands.
Command Enhancement
Regarding the db. prefix enhancement for raw MongoDB commands:
- You can omit the
db.prefix and use the collection name directly, e.g.,coll1.find()queries thecoll1collection in the current database. - You can use
<databaseName>.<collectionName>.to specify the exact collection, e.g.,myDb.coll1.find()queries thecoll1collection in themyDbdatabase. - You can use
use databaseNameto switch the current database.
Collection Operations
| Command | Description | Official Docs |
|---|---|---|
find | Query documents, supports limit, skip, sort, explain, hint | find |
findOne | Query a single document | findOne |
insert | Insert documents | insert |
insertOne | Insert a single document | insertOne |
insertMany | Insert multiple documents | insertMany |
update | Update documents | update |
updateOne | Update a single document | updateOne |
updateMany | Update multiple documents | updateMany |
replaceOne | Replace a single document | replaceOne |
remove | Delete documents | delete |
deleteOne | Delete a single document | deleteOne |
deleteMany | Delete multiple documents | deleteMany |
count | Count documents | count |
distinct | Get distinct values | distinct |
aggregate | Aggregation operations | aggregate |
bulkWrite | Bulk write operations | bulkWrite |
renameCollection | Rename collection | renameCollection |
drop | Drop collection | drop |
Database Management
| Command | Description | Official Docs |
|---|---|---|
createCollection | Create collection | create |
createView | Create view | createView |
dropDatabase | Drop current database | dropDatabase |
getCollectionNames | Get collection name list | listCollections |
getCollectionInfos | Get collection info | listCollections |
runCommand | Run arbitrary database command | runCommand |
serverStatus | Get server status | serverStatus |
stats | Get database statistics | dbStats |
version | Get server version | buildInfo |
Index Management
| Command | Description | Official Docs |
|---|---|---|
createIndex | Create index | createIndexes |
dropIndex | Drop index | dropIndexes |
getIndexes | Get index list | listIndexes |
User Management
| Command | Description | Official Docs |
|---|---|---|
createUser | Create user | createUser |
dropUser | Drop user | dropUser |
updateUser | Update user | updateUser |
changeUserPassword | Change user password | updateUser |
grantRolesToUser | Grant roles to user | grantRolesToUser |
revokeRolesFromUser | Revoke roles from user | revokeRolesFromUser |
Other Commands
use <database>: Switch current database.show dbs: Show all databases.show collections: Show all collections in the current database.show tables: Same asshow collections.
Hint Support
jdbc-mongo supports overriding or enhancing query behavior through SQL Hints. The Hint format is /*+ hint_name=value */ and must be placed at the beginning of the SQL statement.
| Hint Name | Description | Example |
|---|---|---|
overwrite_find_limit | Override the query's limit parameter for pagination or limiting returned rows. | /*+ overwrite_find_limit=10 */ db.collection.find({}) |
overwrite_find_skip | Override the query's skip parameter to skip a specified number of rows for pagination. | /*+ overwrite_find_skip=20 */ db.collection.find({}) |
overwrite_find_as_count | Convert the query to a Count operation, ignoring returned document content and returning only the match count. | /*+ overwrite_find_as_count */ db.collection.find({}) |