Skip to content
广告❤️成为赞助商

Configuration File ​

This article explains the configuration options for MongoPlus

Basic Configuration ​

This section includes most of the commonly used configurations by users, some of which are supported natively by MongoDB.

Usage ​

Spring Boot:

yaml
mongo-plus:
  ......
  configuration:
    ......
  data:
    ......
yml
mongo-plus:
  data:
    mongodb:
      host: 127.0.0.1
      port: 27017
      username: root
      password: root
      database: mp
      connectTimeoutMS: 50000    
      authenticationDatabase: admin
  log: true

Log Configuration ​

MongoPlus log configuration

log ​

  • Type: Boolean
  • Default: false

Whether to enable log output, default is false

logOrder ​

  • Type: Integer
  • Default: 0

Specifies the order of the log interceptor in the interceptor chain

format ​

  • Type: Boolean
  • Default: false

Whether to enable formatted logs

pretty ​

  • Type: Boolean
  • Default: false

Whether to convert printed commands into executable MongoDB statements

Log Configuration Example ​

yml
mongo-plus:
  log: true
  format: true
  pretty: true

Field Configuration ​

camelToUnderline ​

  • Type: Boolean
  • Default: false

Whether to enable camelCase to underscore conversion

ignoringNull ​

  • Type: Boolean
  • Default: true

Whether to ignore null properties

Field Configuration Example ​

yml
mongo-plus:
  configuration:
    field:
      camelToUnderline: true
      ignoringNull: false

Collection Configuration ​

mappingStrategy ​

  • Type: CollectionNameConvertEnum
  • Default: null

Collection name mapping strategy Options: ALL_CHAR_LOWERCASE (class name all lowercase, default); FIRST_CHAR_LOWERCASE (first character lowercase); CLASS_NAME (class name); CAMEL_TO_UNDERLINE (camel case to underscore)

blockAttackInner ​

  • Type: Boolean
  • Default: false

Enable prevention of full collection update and delete (prevent full table update/delete)

Collection Configuration Example ​

yaml
mongo-plus:
  configuration:
    collection:
      mappingStrategy: CLASS_NAME
      block-attack-inner: true
  • Type: Boolean
  • Default: true

Set to false to disable banner printing

ikun ​

  • Type: Boolean
  • Default: true

Set true to enable "little black mode"

yaml
mongo-plus:
  configuration:
    banner: false
    ikun: true

Auto-increment ID Collection Name Configuration ​

autoIdCollectionName ​

  • Type: String
  • Default: counters
yaml
mongo-plus:
  configuration:
    autoIdCollectionName: xxxx

Auto Convert ObjectId Configuration ​

autoConvertObjectId ​

  • Type: boolean
  • Default: true
yaml
mongo-plus:
  configuration:
    autoConvertObjectId: true

Auto Create Index Configuration ​

autoCreateIndex ​

  • Type: boolean
  • Default: false
yaml
mongo-plus:
  configuration:
    autoCreateIndex: true

Auto Create TimeSeries Collection Configuration ​

autoCreateTimeSeries ​

  • Type: boolean
  • Default: false
yaml
mongo-plus:
  configuration:
    autoCreateTimeSeries: true

Spring Configuration ​

transaction ​

  • Type: boolean
  • Default: false

Whether to use Spring's @Transactional annotation to control Mongo transactions

Spring Configuration Example ​

yaml
mongo-plus:
  spring:
    transaction: true

Logical Delete Configuration ​

open ​

  • Type: boolean
  • Default: false

Whether to enable logical delete functionality

auto-fill ​

  • Type: boolean
  • Default: false

Whether to enable default logical field filling functionality

logic-delete-field ​

  • Type: String
  • Default: null

Global logical delete field (corresponding MongoDB document field, required when logical delete is enabled)

logic-delete-value ​

  • Type: String
  • Default: 1

Marks global logical delete

logic-not-delete-value ​

  • Type: String
  • Default: 0

Marks global logical not deleted

logic-data-type ​

  • Type: LogicDataType
  • Default: String

Data type of global logical delete field, default String

Logical Delete Configuration Example ​

yaml
mongo-plus:
  configuration:
    logic:
      open: true                    # Enable logical delete functionality
      auto-fill: true               # Enable interceptor auto fill logical delete field, effective only when logical delete is enabled
      logic-delete-field: logicDel  # Global logical delete field (string type)
      logic-delete-value: 1         # Mark logical delete value
      logic-not-delete-value: 0     # Mark logical not deleted value
      logic-data-type: integer      # Re-specify data type as Integer

Global Encryption Configuration ​

privateKey ​

  • Type: String
  • Default: null

Private key, asymmetric encryption

publicKey ​

  • Type: String
  • Default: null

Public key, asymmetric encryption

key ​

  • Type: String
  • Default: null

Key, symmetric encryption

Example ​

yaml
mongo-plus:
  encryptor:
    privateKey: XXX
    publicKey: XXX
    key: XXX

MongoDB Properties Configuration ​

url ​

  • Type: String
  • Default: null

Full MongoDB URL path, configuring this path will make the related URL configurations below ineffective. Using this URL can allow SSL connection, but database configuration is still required.

Example ​

yaml
mongo-plus:
  data:
    mongodb:
      url: mongodb://test:test@127.0.0.1:27017/admin?connectTimeoutMS=50000
      database: mp

host ​

  • Type: String
  • Default: null

MongoDB address (comma separated for replica sets)

port ​

  • Type: String
  • Default: null

MongoDB port, if multiple hosts have different ports, separate with commas. If the same, can ignore.

username ​

Username, if account contains @, !, etc., no need to encode

password ​

Password, if contains @, !, etc., no need to encode

authenticationDatabase ​

Authentication database, configure here if authentication is enabled

minPoolSize ​

Minimum connections in single pool, default 0

maxPoolSize ​

Maximum connections in single pool, default 100

waitQueueTimeoutMS ​

Maximum time (ms) a thread waits for connection to become available, default 120 seconds

serverSelectionTimeoutMS ​

Maximum time (ms) driver waits before throwing exception when selecting server, default 30 seconds

localThresholdMS ​

When communicating with multiple MongoDB instances in replica set, driver sends requests only to servers with response time less than or equal to the fastest + local threshold (ms), default 15

heartbeatFrequencyMS ​

Frequency (ms) driver waits between checking each server state in the cluster, default 10ms

replicaSet ​

Name of replica set if connecting to multiple hosts, default null

ssl ​

Whether all communication with MongoDB uses TLS/SSL, replaced by tls option, default false

tls ​

Whether all communication uses TLS, replaces ssl, default false

tlsInsecure ​

Whether to allow invalid hostnames in TLS connection, same effect as tlsAllowInvalidHostnames=true, default false

tlsAllowInvalidHostnames ​

Whether to allow invalid hostnames in certificate for TLS connection, replaces sslInvalidHostName, default false

connectTimeoutMS ​

Maximum time (ms) driver waits for connection to open before timeout, 0 means never timeout, default 10ms

socketTimeoutMS ​

Maximum time (ms) driver waits for send/receive requests before timeout, 0 means never timeout, default 0

maxIdleTimeMS ​

Maximum idle time (ms) for pool connection before closing, 0 means no limit, default 0

maxLifeTimeMS ​

Maximum lifetime (ms) of pool connection before closing, 0 means unlimited, default 0

journal ​

Whether driver must wait for MongoDB instance to group commit to disk for all writes, default false

w ​

Write concern, see official docs for values, default 1

wtimeoutMS ​

Write concern timeout in ms, see official docs, 0 means never timeout, default 0

readPreference ​

Read preference, see official docs, default primary

readPreferenceTags ​

Read preference tags, see official docs, default null

maxStalenessSeconds ​

  • Maximum staleness in seconds for secondary before driver stops communicating. Minimum 90 or heartbeatFrequency+10, whichever is larger.
  • See official docs for details. No parameter or -1 disables staleness check, default -1

authMechanism ​

Authentication mechanism to use when providing credentials, driver chooses safest by default

authSource ​

Database to authenticate credentials, default admin

authMechanismProperties ​

Properties for specified authentication mechanism, list of key:value pairs, default null

appName ​

Application name provided to MongoDB during connection handshake, used in logs and analytics, default null

compressors ​

Compression algorithms driver tries to use, options: zlib, snappy, zstd, default null

zlibCompressionLevel ​

Zlib compression level, -1 to 9, lower=faster/higher size, higher=slower/smaller size, default null

retryWrites ​

Whether to retry supported write operations on network errors, default true

retryReads ​

Whether to retry supported read operations on network errors, default true

uuidRepresentation ​

UUID representation for read/write operations, see MongoClientSettings.getUuidRepresentation(), default unspecified

directConnection ​

Whether driver must connect directly to host, default false

maxConnecting ​

Maximum simultaneous connections driver can establish, default 2

srvServiceName ​

Service name for retrieving SRV records to build seed list, must use DNS seed list URI format, default mongodb