Jess182J
Denoβ€’4y agoβ€’
14 replies
Jess182

Problem with Mongoose + auth

Hi i followed the mongoose example provided by denoland, but if my local database has authentication, mongoose not connect (it freeze on
connect
statemment)

example: https://github.com/denoland/examples/tree/main/with-mongoose

import mongoose, { model, Schema } from 'npm:mongoose@^6.7';

const dinosaurSchema = new Schema({
  name: { type: String, unique: true },
  description: String,
  createdAt: { type: Date, default: Date.now },
  updatedAt: { type: Date, default: Date.now },
});

const Dinosaur = model('Dinosaur', dinosaurSchema);

// await mongoose.connect('mongodb://localhost:27017');

await mongoose.connect('mongodb://username:password@localhost:27017');

// Check to see connection status.
console.log(mongoose.connection.readyState);

console.log(await Dinosaur.find());


Note: same URI works with node + mongoose
Was this page helpful?