I’ve passed all MongoDB challenges up to MongoDB and Mongoose - Create and Save a Record of a Model. When I submit my repl url, I always get the error:
// running tests
Creating and saving a db item should succeed (Test timed out)
// tests completed
Here is my code so far for myApp.js:
const mongoose = require("mongoose");
mongoose.connect(process.env.MONGO_URI, {useNewUrlParser: true, useUnifiedTopology: true});
var Schema = mongoose.Schema;
const PersonSchema = new Schema({
name: { type: String, required: true },
age: Number,
favoriteFoods: [String]
});
const Person = mongoose.model("Person", PersonSchema)
var createAndSavePerson = function(done) {
const taylor = new Person({name: "taylor", age: 31, favoriteFoods: ["Pad Thai", "Fettucine Alfredo"]});
taylor.save(function(error, data){
if(error) return console.error(error);
done(null, data);
});
};
and my .env:
MONGO_URI="mongodb+srv://fcc2:<myPassword>@fcc.tbyo9.mongodb.net/fccDB?retryWrites=true&w=majority";
I thought it was an issue with the connection string, so I followed steps in this article https://docs.mongodb.com/manual/reference/connection-string/, but had no luck. I also deleted the user, ip whitelist, and database from my mongo cluster and recreated them thinking that I did something wrong there, but that didn’t help. I looked at the provided solution, and as far I can tell, I have the same code. I also tried logging the mongoose object and see this, which seems to indicate it isn’t connecting:
Mongoose {
connections:
[ NativeConnection {
base: [Circular],
collections: [Object],
models: [Object],
config: [Object],
replica: false,
options: null,
otherDbs: [],
relatedDbs: {},
states: [Object],
_readyState: 2,
_closeCalled: false,
_hasOpened: false,
plugins: [],
id: 0,
_listening: false,
_connectionOptions: [Object],
client: [MongoClient],
'$initialConnection': [Promise],
then: [Function],
catch: [Function] } ]
Is the end-point I provide supposed to be something other than the base url of my repl? Any ideas what I’m doing wrong?
Thanks in advance!
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36
.
Challenge: Create and Save a Record of a Model
Link to the challenge: