Commands
Hint
This article is generated by AI translation.
jdbc-mongo converts raw Command instructions into underlying API calls by parsing them. The following is a list of supported commands.
Command enhancements
For MongoDB commands that normally use the db. prefix:
- You may omit
db.and use the collection name directly, e.g.,coll1.find()queries collectioncoll1in the current database. - You may use
<db>.<collection>.to target a specific database/collection, e.g.,myDb.coll1.find()queriescoll1in databasemyDb. - You may switch databases with
use <database>.
Collection Operations
| Command | Description | Docs |
|---|---|---|
find | Query documents; supports limit, skip, sort, explain, hint | find |
findOne | Query a single document | findOne |
insert | Insert documents | insert |
insertOne | Insert one document | insertOne |
insertMany | Insert many documents | insertMany |
update | Update documents | update |
updateOne | Update one document | updateOne |
updateMany | Update many documents | updateMany |
replaceOne | Replace one document | replaceOne |
remove | Delete documents | delete |
deleteOne | Delete one document | deleteOne |
deleteMany | Delete many documents | deleteMany |
count | Count documents | count |
distinct | Get distinct values | distinct |
aggregate | Aggregation | aggregate |
bulkWrite | Bulk writes | bulkWrite |
renameCollection | Rename collection | renameCollection |
drop | Drop collection | drop |
Database Management
| Command | Description | Docs |
|---|---|---|
createCollection | Create collection | create |
createView | Create view | createView |
dropDatabase | Drop current database | dropDatabase |
getCollectionNames | List collection names | listCollections |
getCollectionInfos | Get collection info | listCollections |
runCommand | Run any DB command | runCommand |
serverStatus | Get server status | serverStatus |
stats | Get DB stats | dbStats |
version | Get server version | buildInfo |
Index Management
| Command | Description | Docs |
|---|---|---|
createIndex | Create index | createIndexes |
dropIndex | Drop index | dropIndexes |
getIndexes | List indexes | listIndexes |
User Management
| Command | Description | Docs |
|---|---|---|
createUser | Create user | createUser |
dropUser | Drop user | dropUser |
updateUser | Update user | updateUser |
changeUserPassword | Change user password | updateUser |
grantRolesToUser | Grant roles | grantRolesToUser |
revokeRolesFromUser | Revoke roles | revokeRolesFromUser |
Other Commands
use <database>: switch current database.show dbs: list all databases.show collections: list all collections in the current DB.show tables: same asshow collections.
Hint Support
jdbc-mongo supports overriding or enhancing query behavior via SQL Hint. 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 | Overrides the limit parameter of the query, used for pagination or limiting the number of returned records. | /*+ overwrite_find_limit=10 */ db.collection.find({}) |
overwrite_find_skip | Overrides the skip parameter of the query, used for pagination to skip a specified number of records. | /*+ overwrite_find_skip=20 */ db.collection.find({}) |
overwrite_find_as_count | Converts the query to a Count operation, ignoring the returned document content and returning only the match count. | /*+ overwrite_find_as_count */ db.collection.find({}) |