mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: update to mongodb5 (#514)
This commit is contained in:
1 parent
5a02010120
commit
0685b88066
59 files changed
+610
-601
No files matched your search
@@ -3,7 +3,7 @@
|
||||
import path from 'path';
|
||||
import cac from 'cac';
|
||||
import fs from 'fs-extra';
|
||||
import { ObjectID } from 'mongodb';
|
||||
import { ObjectId } from 'mongodb';
|
||||
import { Context } from '../context';
|
||||
import db from '../service/db';
|
||||
import {
|
||||
@@ -67,8 +67,8 @@ async function cli() {
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
if ("'\"".includes(args[i][0]) && "'\"".includes(args[i][args[i].length - 1])) {
|
||||
args[i] = args[i].substr(1, args[i].length - 2);
|
||||
} else if (args[i].length === 24 && ObjectID.isValid(args[i])) {
|
||||
args[i] = new ObjectID(args[i]);
|
||||
} else if (args[i].length === 24 && ObjectId.isValid(args[i])) {
|
||||
args[i] = new ObjectId(args[i]);
|
||||
} else if ((+args[i]).toString() === args[i]) {
|
||||
args[i] = +args[i];
|
||||
} else if (args[i].startsWith('~')) {
|
||||
|
||||
@@ -5,7 +5,7 @@ import cac from 'cac';
|
||||
import fs from 'fs-extra';
|
||||
import Koa, { Context } from 'koa';
|
||||
import Body from 'koa-body';
|
||||
import mongodb from 'mongodb';
|
||||
import { MongoClient, WriteConcern } from 'mongodb';
|
||||
import { Logger } from '../logger';
|
||||
|
||||
const logger = new Logger('setup');
|
||||
@@ -85,11 +85,12 @@ async function post(ctx: Context) {
|
||||
if (username) mongourl += `${username}:${password}@`;
|
||||
mongourl += `${host}:${port}/${name}`;
|
||||
try {
|
||||
const Database = await mongodb.MongoClient.connect(mongourl, {
|
||||
useNewUrlParser: true, useUnifiedTopology: true,
|
||||
const Database = await MongoClient.connect(mongourl, {
|
||||
readPreference: 'nearest',
|
||||
writeConcern: new WriteConcern('majority'),
|
||||
});
|
||||
const db = Database.db(name);
|
||||
const coll = db.collection('system');
|
||||
const coll = db.collection<any>('system');
|
||||
await Promise.all([
|
||||
coll.updateOne(
|
||||
{ _id: 'server.url' },
|
||||
|
||||
Reference in new issue
Block a user