mongoose-shortid icon indicating copy to clipboard operation
mongoose-shortid copied to clipboard

Missing "let" in index.js when using strict mode

Open skosch opened this issue 10 years ago • 0 comments

Hi,

I'm running node in strict mode and I'm getting

/apiserver/node_modules/mongoose-shortid/lib/index.js:6
  for (fieldName in this.schema.tree) {
                               ^
ReferenceError: fieldName is not defined
    at model.mongoose.Model.save (/apiserver/node_modules/mongoose-shortid/lib/index.js:6:32)
    at model._done (/apiserver/node_modules/mongoose/node_modules/hooks/hooks.js:59:24)
    at _next (/apiserver/node_modules/mongoose/node_modules/hooks/hooks.js:52:28)
    at fnWrapper (/apiserver/node_modules/mongoose/node_modules/hooks/hooks.js:159:8)
    at model.<anonymous> (/apiserver/node_modules/mongoose-schema-extend/index.js:44:7)
    at _next (/apiserver/node_modules/mongoose/node_modules/hooks/hooks.js:50:30)
    at fnWrapper (/apiserver/node_modules/mongoose/node_modules/hooks/hooks.js:159:8)
    at model.<anonymous> (/apiserver/node_modules/mongoose-schema-extend/index.js:44:7)
    at _next (/apiserver/node_modules/mongoose/node_modules/hooks/hooks.js:50:30)
    at fnWrapper (/apiserver/node_modules/mongoose/node_modules/hooks/hooks.js:159:8)

In strict mode, the problem is easily fixed by writing for (let fieldName ... instead (but let doesn't work in legacy mode, of course). Maybe you could check for strict mode, or traverse the schema some other way?

skosch avatar Jan 14 '15 03:01 skosch