Instruction file imported from JesynLee/esports-gear-review (
.cursor/rules/database_connection_info.mdc). Copyright stays with the author.
MongoDB数据库连接信息
当需要在代码中连接MongoDB数据库时,请使用以下连接信息:
基础信息
- 数据库类型: MongoDB
- 版本: MongoDB 6.0
- 创建时间: 2025/05/31 06:51
配置信息
- 最大CPU: 0.5 Core
- 最大内存: 512 Mi
- 磁盘: 1Gi
连接信息
- 用户名: root
- 密码: qwer1234
- 内网主机: lzcdb-mongodb.ns-vayjj8h0.svc
- 端口: 27017
- 连接字符串: mongodb://root:qwer1234@lzcdb-mongodb.ns-vayjj8h0.svc:27017
连接示例
Node.js (使用MongoDB驱动)
const { MongoClient } = require('mongodb');
const uri = 'mongodb://root:lgsIqIxv@lzcdb-mongodb.ns-vayjj8h0.svc:27017';
const client = new MongoClient(uri);
async function connect() {
try {
await client.connect();
console.log('已成功连接到MongoDB数据库');
return client.db('你的数据库名称');
} catch (error) {
console.error('连接到MongoDB时出错:', error);
throw error;
}
}
Python (使用pymongo)
from pymongo import MongoClient
uri = 'mongodb://root:lgsIqIxv@lzcdb-mongodb.ns-vayjj8h0.svc:27017'
client = MongoClient(uri)
try:
# 测试连接
client.admin.command('ping')
print("已成功连接到MongoDB数据库")
db = client['你的数据库名称']
except Exception as e:
print("连接到MongoDB时出错:", e)
注意事项
- 请确保应用程序所在的环境能够访问此MongoDB实例
- 生产环境中应避免在代码中硬编码连接字符串,建议使用环境变量或配置文件
- 连接时可能需要指定额外的连接选项,如认证数据库、SSL设置等