Problem with urlshortener

I am trying to complete the urlshortener challenge using the mongoose odm to communicated with a mongodb database on my machine

    var express = require('express');
    var validUrl = require('valid-url');
    var path = require('path');
    var mongodb = require('mongodb')
    var mongoose = require('mongoose');

    var app = express()


    var urlNumberSchema = new mongoose.Schema({
    	urlNumber: {
    		type: Number

    var urlSchema = new mongoose.Schema({
    	originalUrl: {
    		type: String,
    		required: true
    	shortUrl: {
    		type: String,
    		required: true

    var UrlNumber = new mongoose.model('UrlNumber',urlNumberSchema)

    var Url = new mongoose.model('Url',urlSchema)


        var uri = req.originalUrl;
        var actualUri = uri.split('api/')[1];
        var status = validUrl.isUri(actualUri)
        console.log('status '+status);


    console.log('Server running on port 3000');

I have the database running on port 27107. However try as I may I get the following error

TypeError: Cannot read property 'UrlNumber' of undefined

What is the problem and how can I solve it?

I’ve only just gotten started with Intro to MongoDB using Mean stack on EdX but could this be about missing quotation marks?

How about removing the new in the new mongoose.model(..) lines?

Also I noticed that you have a uri* parameter in your GET route but you didn’t use it.

1 Like

Removing new worked! Do you have any idea why?

I think that’s just how mongoose works.