You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Log4j配置中指定MongoDB认证数据库以连接非Admin库

解决方法

Log4j的MongoDb3配置支持通过authenticationDatabase属性指定认证数据库,你只需要在配置中添加该属性并设置为你的认证主库admin即可:

<NoSql name="databaseAppender">
    <MongoDb3 databaseName="log" 
              collectionName="log" 
              server="localhost" 
              port="27017" 
              username="test" 
              password="test"
              authenticationDatabase="admin"/>
</NoSql>

添加该属性后,MongoDB驱动会先使用admin数据库完成身份验证,验证通过后再连接到log数据库存储日志。

内容的提问来源于stack exchange,提问作者Ali ZareShahi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 07:54:52