El deploy me regresa los siguientes errores
2021-09-09T03:48:59.266113+00:00 app[web.1]: > node dist/main
2021-09-09T03:48:59.266113+00:00 app[web.1]:
2021-09-09T03:49:00.018565+00:00 app[web.1]: (node:22) Warning: Accessing non-existent property 'MongoError' of module exports inside circular dependency
2021-09-09T03:49:00.018585+00:00 app[web.1]: (Use `node --trace-warnings ...` to show where the warning was created)
2021-09-09T03:49:00.038000+00:00 app[web.1]: [Nest] 22 - 09/09/2021, 3:49:00 AM [NestFactory] Starting Nest application...
2021-09-09T03:49:00.065424+00:00 app[web.1]: [Nest] 22 - 09/09/2021, 3:49:00 AM [InstanceLoader] MongooseModule dependencies initialized +45ms
2021-09-09T03:49:00.065810+00:00 app[web.1]: conexion2 mongodb+srv://usuario:password@platzi-store.dominio.mongodb.net
2021-09-09T03:49:00.069052+00:00 app[web.1]: client MongoClient {
2021-09-09T03:49:00.069054+00:00 app[web.1]: _events: [Object: null prototype] {},
2021-09-09T03:49:00.069054+00:00 app[web.1]: _eventsCount: 0,
2021-09-09T03:49:00.069054+00:00 app[web.1]: _maxListeners: undefined,
2021-09-09T03:49:00.069055+00:00 app[web.1]: s: {
2021-09-09T03:49:00.069056+00:00 app[web.1]: url: 'mongodb+srv://usuario:password@platzi-store.dominio.mongodb.net',
2021-09-09T03:49:00.069056+00:00 app[web.1]: options: {},
2021-09-09T03:49:00.069056+00:00 app[web.1]: promiseLibrary: [Function: Promise],
2021-09-09T03:49:00.069057+00:00 app[web.1]: dbCache: Map(0) {},
2021-09-09T03:49:00.069057+00:00 app[web.1]: sessions: Set(0) {},
2021-09-09T03:49:00.069057+00:00 app[web.1]: writeConcern: undefined,
2021-09-09T03:49:00.069058+00:00 app[web.1]: readPreference: ReadPreference {
2021-09-09T03:49:00.069058+00:00 app[web.1]: mode: 'primary',
2021-09-09T03:49:00.069059+00:00 app[web.1]: tags: undefined,
2021-09-09T03:49:00.069059+00:00 app[web.1]: hedge: undefined
2021-09-09T03:49:00.069059+00:00 app[web.1]: },
2021-09-09T03:49:00.069060+00:00 app[web.1]: namespace: MongoDBNamespace { db: 'admin', collection: undefined }
2021-09-09T03:49:00.069060+00:00 app[web.1]: },
2021-09-09T03:49:00.069060+00:00 app[web.1]: [Symbol(kCapture)]: false
2021-09-09T03:49:00.069060+00:00 app[web.1]: }
2021-09-09T03:49:00.073755+00:00 app[web.1]: [Nest] 22 - 09/09/2021, 3:49:00 AM [InstanceLoader] HttpModule dependencies initialized +8ms
2021-09-09T03:49:00.096734+00:00 app[web.1]: [Nest] 22 - 09/09/2021, 3:49:00 AM [InstanceLoader] ConfigHostModule dependencies initialized +23ms
2021-09-09T03:49:00.100702+00:00 app[web.1]: [Nest] 22 - 09/09/2021, 3:49:00 AM [InstanceLoader] ConfigModule dependencies initialized +4ms
2021-09-09T03:49:00.105663+00:00 app[web.1]: [Nest] 22 - 09/09/2021, 3:49:00 AM [MongooseModule] Unable to connect to the database. Retrying (1)... +5ms
2021-09-09T03:49:00.117512+00:00 app[web.1]: (node:22) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
2021-09-09T03:49:00.179476+00:00 app[web.1]: database Db {
2021-09-09T03:49:00.179481+00:00 app[web.1]: _events: [Object: null prototype] {},
2021-09-09T03:49:00.179482+00:00 app[web.1]: _eventsCount: 0,
2021-09-09T03:49:00.179482+00:00 app[web.1]: _maxListeners: undefined,
2021-09-09T03:49:00.179483+00:00 app[web.1]: s: {
2021-09-09T03:49:00.179483+00:00 app[web.1]: dbCache: {},
2021-09-09T03:49:00.179483+00:00 app[web.1]: children: [],
2021-09-09T03:49:00.179484+00:00 app[web.1]: topology: ReplSet {
2021-09-09T03:49:00.179484+00:00 app[web.1]: _events: [Object: null prototype],
2021-09-09T03:49:00.179485+00:00 app[web.1]: _eventsCount: 35,
2021-09-09T03:49:00.179485+00:00 app[web.1]: _maxListeners: Infinity,
2021-09-09T03:49:00.179485+00:00 app[web.1]: s: [Object],
2021-09-09T03:49:00.179486+00:00 app[web.1]: [Symbol(kCapture)]: false
2021-09-09T03:49:00.179486+00:00 app[web.1]: },
2021-09-09T03:49:00.179486+00:00 app[web.1]: options: {
2021-09-09T03:49:00.179487+00:00 app[web.1]: authSource: 'admin',
2021-09-09T03:49:00.179487+00:00 app[web.1]: retryWrites: true,
2021-09-09T03:49:00.179487+00:00 app[web.1]: readPreference: [ReadPreference],
2021-09-09T03:49:00.179488+00:00 app[web.1]: promiseLibrary: [Function: Promise]
2021-09-09T03:49:00.179488+00:00 app[web.1]: },
2021-09-09T03:49:00.179488+00:00 app[web.1]: logger: Logger { className: 'Db' },
2021-09-09T03:49:00.179488+00:00 app[web.1]: bson: BSON {},
2021-09-09T03:49:00.179489+00:00 app[web.1]: readPreference: ReadPreference {
2021-09-09T03:49:00.179489+00:00 app[web.1]: mode: 'primary',
2021-09-09T03:49:00.179489+00:00 app[web.1]: tags: undefined,
2021-09-09T03:49:00.179490+00:00 app[web.1]: hedge: undefined
2021-09-09T03:49:00.179490+00:00 app[web.1]: },
2021-09-09T03:49:00.179490+00:00 app[web.1]: bufferMaxEntries: -1,
2021-09-09T03:49:00.179490+00:00 app[web.1]: parentDb: null,
2021-09-09T03:49:00.179491+00:00 app[web.1]: pkFactory: undefined,
2021-09-09T03:49:00.179491+00:00 app[web.1]: nativeParser: undefined,
2021-09-09T03:49:00.179491+00:00 app[web.1]: promiseLibrary: [Function: Promise],
2021-09-09T03:49:00.179492+00:00 app[web.1]: noListener: false,
2021-09-09T03:49:00.179492+00:00 app[web.1]: readConcern: undefined,
2021-09-09T03:49:00.179492+00:00 app[web.1]: writeConcern: undefined,
2021-09-09T03:49:00.179493+00:00 app[web.1]: namespace: MongoDBNamespace { db: 'platzi-store', collection: undefined }
2021-09-09T03:49:00.179493+00:00 app[web.1]: },
2021-09-09T03:49:00.179494+00:00 app[web.1]: serverConfig: [Getter],
2021-09-09T03:49:00.179494+00:00 app[web.1]: bufferMaxEntries: [Getter],
2021-09-09T03:49:00.179494+00:00 app[web.1]: databaseName: [Getter],
2021-09-09T03:49:00.179496+00:00 app[web.1]: [Symbol(kCapture)]: false
2021-09-09T03:49:00.179496+00:00 app[web.1]: }
2021-09-09T03:49:00.179898+00:00 app[web.1]: [Nest] 22 - 09/09/2021, 3:49:00 AM [InstanceLoader] DatabaseModule dependencies initialized +74ms
2021-09-09T03:49:00.180578+00:00 app[web.1]: [Nest] 22 - 09/09/2021, 3:49:00 AM [InstanceLoader] AppModule dependencies initialized +1ms
2021-09-09T03:49:03.112053+00:00 app[web.1]: [Nest] 22 - 09/09/2021, 3:49:03 AM [MongooseModule] Unable to connect to the database. Retrying (2)... +2931ms
2021-09-09T03:49:06.116810+00:00 app[web.1]: [Nest] 22 - 09/09/2021, 3:49:06 AM [MongooseModule] Unable to connect to the database. Retrying (3)... +3005ms
2021-09-09T03:49:09.120308+00:00 app[web.1]: [Nest] 22 - 09/09/2021, 3:49:09 AM [MongooseModule] Unable to connect to the database. Retrying (4)... +3003ms
2021-09-09T03:49:12.124414+00:00 app[web.1]: [Nest] 22 - 09/09/2021, 3:49:12 AM [MongooseModule] Unable to connect to the database. Retrying (5)... +3005ms
2021-09-09T03:49:15.128907+00:00 app[web.1]: [Nest] 22 - 09/09/2021, 3:49:15 AM [MongooseModule] Unable to connect to the database. Retrying (6)... +3004ms
2021-09-09T03:49:18.132875+00:00 app[web.1]: [Nest] 22 - 09/09/2021, 3:49:18 AM [MongooseModule] Unable to connect to the database. Retrying (7)... +3004ms
2021-09-09T03:49:21.136517+00:00 app[web.1]: [Nest] 22 - 09/09/2021, 3:49:21 AM [MongooseModule] Unable to connect to the database. Retrying (8)... +3004ms
2021-09-09T03:49:24.140900+00:00 app[web.1]: [Nest] 22 - 09/09/2021, 3:49:24 AM [MongooseModule] Unable to connect to the database. Retrying (9)... +3004ms
2021-09-09T03:49:24.141777+00:00 app[web.1]: [Nest] 22 - 09/09/2021, 3:49:24 AM [ExceptionHandler] querySrv ENOTFOUND _mongodb._tcp.ajumx.mongodb.net +1ms
2021-09-09T03:49:24.141797+00:00 app[web.1]: Error: querySrv ENOTFOUND _mongodb._tcp.ajumx.mongodb.net
2021-09-09T03:49:24.141798+00:00 app[web.1]: at QueryReqWrap.onresolve [as oncomplete] (dns.js:206:19)
2021-09-09T03:49:24.152186+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2021-09-09T03:49:24.152420+00:00 app[web.1]: npm ERR! errno 1
2021-09-09T03:49:24.157907+00:00 app[web.1]: npm ERR! platzi-store@0.0.1 start:prod: `node dist/main`
2021-09-09T03:49:24.158000+00:00 app[web.1]: npm ERR! Exit status 1
2021-09-09T03:49:24.158115+00:00 app[web.1]: npm ERR!
2021-09-09T03:49:24.158194+00:00 app[web.1]: npm ERR! Failed at the platzi-store@0.0.1 start:prod script.
2021-09-09T03:49:24.158269+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2021-09-09T03:49:24.161554+00:00 app[web.1]:
2021-09-09T03:49:24.161704+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-09-09T03:49:24.161773+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2021-09-09T03_49_24_158Z-debug.log
2021-09-09T03:49:24.222312+00:00 heroku[web.1]: Process exited with status 1
2021-09-09T03:49:24.277771+00:00 heroku[web.1]: State changed from starting to crashed
2021-09-09T03:49:41.161489+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=calm-bayou-72866.herokuapp.com request_id=ce6edeec-1b00-495c-9c73-45e87a9127c2 fwd="177.245.201.47" dyno= connect= service= status=503 bytes= protocol=https
Mi archivo database.module
import { Module, Global } from '@nestjs/common';
import { ConfigType } from '@nestjs/config';
import { MongooseModule } from '@nestjs/mongoose';
import { MongoClient } from 'mongodb';
import config from '../config';
const API_KEY = '12345634';
const API_KEY_PROD = '12345634';
// const taskCollection = database.collection('tasks');
// const tasks = await taskCollection.find().toArray();
@Global()
@Module({
imports: [
// MongooseModule.forRoot('mongodb://localhost:27017', {
// user: 'root',
// pass: 'root',
// dbName: 'platzi-store',
// }),
MongooseModule.forRootAsync({
useFactory: (configService: ConfigType<typeof config>) => {
const {
connection,
user,
password,
host,
dbName,
} = configService.mongo;
return {
uri: `${connection}://${host}`,
user,
pass: password,
dbName,
};
},
inject: [config.KEY],
}),
],
providers: [
{
provide: 'API_KEY',
useValue: process.env.NODE_ENV === 'prod' ? API_KEY_PROD : API_KEY,
},
{
provide: 'MONGO',
useFactory: async (configService: ConfigType<typeof config>) => {
const {
connection,
user,
password,
host,
dbName,
} = configService.mongo;
const uri = `${connection}://${user}:${password}@${dbName}.${host}`;
console.log("conexion2",uri);
const client = new MongoClient(uri);
console.log("client",client);
await client.connect();
const database = client.db(dbName);
console.log("database",database);
return database;
},
inject: [config.KEY],
},
],
exports: ['API_KEY', 'MONGO', MongooseModule],
})
export class DatabaseModule {}