update
This commit is contained in:
parent
51388d5057
commit
1c108f3599
|
|
@ -9,15 +9,20 @@ let mongoClientSingleton: MongoClient
|
|||
let mongoUrl: string
|
||||
|
||||
const getMongoClient = async (newMongoUrl: string) => {
|
||||
if (!mongoClientSingleton || newMongoUrl !== mongoUrl) {
|
||||
if (!mongoClientSingleton) {
|
||||
// if client doesn't exists
|
||||
mongoClientSingleton = new MongoClient(newMongoUrl)
|
||||
mongoUrl = newMongoUrl
|
||||
return mongoClientSingleton
|
||||
} else if (mongoClientSingleton && newMongoUrl !== mongoUrl) {
|
||||
// if client exists but url changed
|
||||
mongoClientSingleton.close()
|
||||
mongoClientSingleton = new MongoClient(newMongoUrl)
|
||||
mongoUrl = newMongoUrl
|
||||
await mongoClientSingleton.connect()
|
||||
return mongoClientSingleton
|
||||
}
|
||||
return mongoClientSingleton
|
||||
}
|
||||
|
||||
class MongoDB_Memory implements INode {
|
||||
label: string
|
||||
name: string
|
||||
|
|
|
|||
Loading…
Reference in New Issue