t3chnoboy/koa-mongo-rest

Error on running example

wentingliu opened this issue · 3 comments

I ran the below code:

var createModel = require('koa-mongo-rest');

var schema = {
  schema: {
    email: String,
    name: String,
    password: String,
    address: String,
    zipcode: Number,
    lists: Array
  },
  collectionName: 'user'
};


var koa = require('koa');
var router = require('koa-router');

var mongoUrl = '127.0.0.1:27017'
var app = koa();
app.use(router(app));
var model = app.model = createModel(schema, mongoUrl);
model.generateApi(app);

app.listen(process.env.PORT || 5000);

and got error:

  return pluralize(name.toLowerCase());
                        ^
TypeError: Cannot call method 'toLowerCase' of undefined
    at exports.toCollectionName (/Users/XXXX/node_modules/mongoose/lib/utils.js:28:25)
    at Mongoose.model (/Users/XXXX/node_modules/mongoose/lib/index.js:361:46)
    at model (/Users/XXXX/node_modules/koa-mongo-rest/lib/model.js:11:19)
    at api (/Users/XXXX/node_modules/koa-mongo-rest/lib/index.js:10:11)
    at Object.<anonymous> (/Users/XXXX/Downloads/koa-mongo-rest-master/example/app.js:22:9)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:349:32)
    at Function.Module._load (module.js:305:12)
    at Function.Module.runMain (module.js:490:10)

I also ran the example in koa-mongo-rest/example, it did lanuch successfully, but when I changed createModel = require('../lib/index'); to createModel = require('koa-mongo-rest');, the same error occurred.

Are you using a version installed from npm?
I've changed api, but haven't published it to npm yet.
I'll publish it as soon as I cover all code with tests. Hopefully today.
To use latest(unpublished) version: npm install --save git://github.com/t3chnoboy/koa-mongo-rest.git

Thanks for your response, the latest works!

I'm glad it helped 😄
I'm going to add some new features and more documentation today.