Node.js 使用Nodejs类型脚本连接到MongoDB不工作
我正在尝试将我的nodejs typescript api连接到MongoDB集群。当我尝试生成迁移时,它返回一个错误 迁移运行期间出错:错误:在中找不到任何连接选项 任何orm配置文件 我的档案如下:Node.js 使用Nodejs类型脚本连接到MongoDB不工作,node.js,mongodb,typescript,typeorm,Node.js,Mongodb,Typescript,Typeorm,我正在尝试将我的nodejs typescript api连接到MongoDB集群。当我尝试生成迁移时,它返回一个错误 迁移运行期间出错:错误:在中找不到任何连接选项 任何orm配置文件 我的档案如下: class App { public app: express.Application; private userRoutes: UserRoutes = new UserRoutes(); private authenticationRoutes: Authenticat
class App {
public app: express.Application;
private userRoutes: UserRoutes = new UserRoutes();
private authenticationRoutes: AuthenticationRoutes = new AuthenticationRoutes();
private common_routes: CommonRoutes = new CommonRoutes();
constructor() {
this.app = express();
this.config();
this.mongoSetup();
this.app.use('/swagger', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
this.initRoutes();
}
private initRoutes() {
this.userRoutes.route(this.app);
this.authenticationRoutes.route(this.app);
this.common_routes.route(this.app);
}
private config(): void {
// support application/json type post data
this.app.use(bodyParser.json());
//support application/x-www-form-urlencoded post data
this.app.use(bodyParser.urlencoded({ extended: false }));
}
private async mongoSetup() {
await createConnection({
type: "mongodb",
host: "localhost",
port: 27017,
database: "test",
useUnifiedTopology: true
}).then( async connection => {
await connection.runMigrations();
}).catch(error => console.log(error));
}
}
export default new App().app;
我正在努力:
npx typeorm migration:create -n first-d lib/core/migrations
npx typeorm migration:generate -n userEntity -d lib/core/migrations
你能列出你的项目文件结构吗?