Tell us what’s happening:
For MongoDB and Mongoose - Create and Save a Record of a Model
Everytime I submit the reply page, the tests on the freecodecamp page say ‘test timed out’.
My bash terminal is showing that there’s a get request.
The terminal is also throwing this error everytime.
Your app is listening on port 3000
(node:2211) UnhandledPromiseRejectionWarning: TypeError: Cannot read property ‘split’ of null
at parseSrvConnectionString (/home/runner/url/node_modules/mongodb/lib/core/uri_parser.js:44:23)
at parseConnectionString (/home/runner/url/node_modules/mongodb/lib/core/uri_parser.js:587:12)
at connect (/home/runner/url/node_modules/mongodb/lib/operations/connect.js:282:3)
at /home/runner/url/node_modules/mongodb/lib/mongo_client.js:223:5
at maybePromise (/home/runner/url/node_modules/mongodb/lib/utils.js:662:3)
at MongoClient.connect (/home/runner/url/node_modules/mongodb/lib/mongo_client.js:219:10)
at /home/runner/url/node_modules/mongoose/lib/connection.js:788:12
at new Promise ()
at NativeConnection.Connection.openUri (/home/runner/url/node_modules/mongoose/lib/connection.js:785:19)
at /home/runner/url/node_modules/mongoose/lib/index.js:342:10
at /home/runner/url/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:5
at new Promise ()
at promiseOrCallback (/home/runner/url/node_modules/mongoose/lib/helpers/promiseOrCallback.js:30:10)
at Mongoose.connect (/home/runner/url/node_modules/mongoose/lib/index.js:341:10)
at Object. (/home/runner/url/myApp.js:4:10)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
(node:2211) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag--unhandled-rejections=strict
(see nodejs. org/ api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
(node:2211) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Your code so far
const mongoose = require(‘mongoose’);
mongoose.connect(process.env.MONGO_URI, { useNewUrlParser: true, useUnifiedTopology: true });
/** 2) Create a ‘Person’ Model /
var personSchema = new mongoose.Schema({
name: { type: String, required: true },
age: Number,
favoriteFoods: [String]
});
/* 3) Create and Save a Person */
var Person = mongoose.model(‘Person’, personSchema);
var createAndSavePerson = async function(done) {
var person = new Person({name: “Jane Fonda”, age: 84, favoriteFoods: [“vodka”, “air”]});
person.save(function(err, data) {
if (err) return console.error(err);
done(null, data)
});
};
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36
.
Challenge: Create and Save a Record of a Model
Link to the challenge: