Skip to content

Commit

Permalink
Merge pull request #134 from jamebal/jmal
Browse files Browse the repository at this point in the history
使用MongoDB URL里的数据库名称
  • Loading branch information
Kerwin1202 authored May 12, 2023
2 parents 3fb11c6 + 9737fd1 commit f3f9fe7
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions service/src/storage/mongo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import type { ChatOptions, Config, UsageResponse } from './model'
dotenv.config()

const url = process.env.MONGODB_URL
const parsedUrl = new URL(url)
const dbName = (parsedUrl.pathname && parsedUrl.pathname !== '/') ? parsedUrl.pathname.substring(1) : 'chatgpt'
const client = new MongoClient(url)
const chatCol = client.db('chatgpt').collection('chat')
const roomCol = client.db('chatgpt').collection('chat_room')
const userCol = client.db('chatgpt').collection('user')
const configCol = client.db('chatgpt').collection('config')
const usageCol = client.db('chatgpt').collection('chat_usage')
const chatCol = client.db(dbName).collection('chat')
const roomCol = client.db(dbName).collection('chat_room')
const userCol = client.db(dbName).collection('user')
const configCol = client.db(dbName).collection('config')
const usageCol = client.db(dbName).collection('chat_usage')

/**
* 插入聊天信息
Expand Down

0 comments on commit f3f9fe7

Please sign in to comment.