我正在通过feathers-mongo
将FeathersJS与MondoDB一起使用
我想以某种方式useUnifiedToplogy:true
传递给连接器的设置,但是它似乎没有在生成的服务中公开(feathers generate service
(
这是我的logging.class.ts
import { Db } from 'mongodb';
import { Service, MongoDBServiceOptions } from 'feathers-mongodb';
import { Application } from '../../declarations';
import {Paginated, Params} from "@feathersjs/feathers";
export class Logging extends Service {
constructor(options: Partial<MongoDBServiceOptions>, app: Application) {
super(options);
const client: Promise<Db> = app.get('mongoClient');
client.then(db => {
this.Model = db.collection('users');
});
}
};
有一个mongodb.ts
在root
import { MongoClient } from 'mongodb';
import { Application } from './declarations';
export default function (app: Application) {
const connection = app.get('mongodb');
const database = connection.substr(connection.lastIndexOf('/') + 1);
const mongoClient = MongoClient.connect(connection, { useNewUrlParser: true, useUnifiedTopology: true })
.then(client => client.db(database));
app.set('mongoClient', mongoClient);
}