0
votes

I get the following error:

TypeError: Cannot read property 'name' of undefined at new SchemaArray (/home/campaigns/scheduler/tests/node_modules/mongoose/lib/schema/array.js:40:22) at Function.interpretAsType (/home/campaigns/scheduler/tests/node_modules/mongoose/lib/schema.js:201:12) at Schema.path (/home/campaigns/scheduler/tests/node_modules/mongoose/lib/schema.js:162:29) at Schema.add (/home/campaigns/scheduler/tests/node_modules/mongoose/lib/schema.js:110:12) at Schema.add (/home/campaigns/scheduler/tests/node_modules/mongoose/lib/schema.js:106:14) at new Schema (/home/campaigns/scheduler/tests/node_modules/mongoose/lib/schema.js:38:10) at Object. (/home/campaigns/scheduler/tests/testSchedulerModel.coffee:12:21) at Object. (/home/campaigns/scheduler/tests/testSchedulerModel.coffee:177:4) at Module._compile (module.js:402:26) at Object.run (/usr/local/lib/node_modules/coffee-script/lib/coffee-script.js:57:25)

However, on line 12 of testSchedulerModel.coffee there is no reference to 'name'. Here is what line 12 looks like: ObjectId = Schema.ObjectId

So how should I understand this error?

Thank you, Igor

2

2 Answers

2
votes

Sigh. Unfortunately, while you'd think testSchedulerModel.coffee:12 would mean "line 12 of testSchedulerModel.coffee, it actually means "line 12 of the JavaScript that testSchedulerModel.coffee is compiled to. The problem is that there's currently no way to trace errors back to the original CoffeeScript (at least not under Node).

So, you'll have to compile testSchedulerModel.coffee as JS and see what line 12 is there.

Better debugging tools for CoffeeScript are coming, but for now, it's probably best that you set up a Cakefile that compiles your code to JS before running it, to avoid such confusion.

By the way, there is an open issue regarding those .coffee filenames in the stack trace: issue 987.

0
votes

Trevor: Kudos for the tip!

I solved my issue. It turns out that I cannot have objects inside of arrays when defining my schema in Mongoose. I was doing it like this:

AdUnitSchema = new mongoose.Schema
  venue: [
    {
      id: ObjectId,
      name: String
    }
  ],
  geotarget: [
    {
    id: ObjectId,
    name: String
    }
  ]

But in actuality, I had to create separate schemas, and reference them like this:

 AdUnitSchema = new mongoose.Schema
        venue:
          [VenueSchema]
        geotarget: 
          [GeotargetSchema]