Skip to main content

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 collection coll1 in the current database.
  • You may use <db>.<collection>. to target a specific database/collection, e.g., myDb.coll1.find() queries coll1 in database myDb.
  • You may switch databases with use <database>.

Collection Operations

CommandDescriptionDocs
findQuery documents; supports limit, skip, sort, explain, hintfind
findOneQuery a single documentfindOne
insertInsert documentsinsert
insertOneInsert one documentinsertOne
insertManyInsert many documentsinsertMany
updateUpdate documentsupdate
updateOneUpdate one documentupdateOne
updateManyUpdate many documentsupdateMany
replaceOneReplace one documentreplaceOne
removeDelete documentsdelete
deleteOneDelete one documentdeleteOne
deleteManyDelete many documentsdeleteMany
countCount documentscount
distinctGet distinct valuesdistinct
aggregateAggregationaggregate
bulkWriteBulk writesbulkWrite
renameCollectionRename collectionrenameCollection
dropDrop collectiondrop

Database Management

CommandDescriptionDocs
createCollectionCreate collectioncreate
createViewCreate viewcreateView
dropDatabaseDrop current databasedropDatabase
getCollectionNamesList collection nameslistCollections
getCollectionInfosGet collection infolistCollections
runCommandRun any DB commandrunCommand
serverStatusGet server statusserverStatus
statsGet DB statsdbStats
versionGet server versionbuildInfo

Index Management

CommandDescriptionDocs
createIndexCreate indexcreateIndexes
dropIndexDrop indexdropIndexes
getIndexesList indexeslistIndexes

User Management

CommandDescriptionDocs
createUserCreate usercreateUser
dropUserDrop userdropUser
updateUserUpdate userupdateUser
changeUserPasswordChange user passwordupdateUser
grantRolesToUserGrant rolesgrantRolesToUser
revokeRolesFromUserRevoke rolesrevokeRolesFromUser

Other Commands

  • use <database>: switch current database.
  • show dbs: list all databases.
  • show collections: list all collections in the current DB.
  • show tables: same as show 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 NameDescriptionExample
overwrite_find_limitOverrides 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_skipOverrides 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_countConverts the query to a Count operation, ignoring the returned document content and returning only the match count./*+ overwrite_find_as_count */ db.collection.find({})