select an existing collection from mongoDB that has not been created with mongoose

PHOTO EMBED

Fri Sep 29 2023 07:51:53 GMT+0000 (Coordinated Universal Time)

Saved by @sadik #mongodb #mongoose #express

/* 
`mongoose.connect` is used to establish a connection to a MongoDB database, while `mongoose.connection` provides access to the active connection and allows you to interact with the database through events and operations.
*/
// see all the methods (https://mongoosejs.com/docs/api/connection.html)

const database = mongoose.connection;
// dbname
database.useDb("users");
// collection name
const collection = database.collection("users");
content_copyCOPY