为什么mongoose model找不到方法
发布于 1年前 作者 sanvibyfish 1048 次浏览

我调用App.checkAppkey出下面得错误 [TypeError: Object function model(doc, fields, skipId) { if (!(this instanceof model)) return new model(doc, fields, skipId); Model.call(this, doc, fields, skipId); } has no method ‘checkAppKey’]

//app.coffee mongoose = require ‘mongoose’ User = require ‘./user’

schema = new mongoose.Schema( private_token: String, user_ids: Array, user_id: { type: mongoose.Schema.Types.ObjectId, ref: ‘User’ }, created_at: {type: Date, default: Date.now}, updated_at: {type: Date, default: Date.now}, name: String, uuid: String, welcome: String )

module.exports = mongoose.model 'App’, schema App = module.exports

module.exports.checkAppkey = (appkey, callback) -> App.findOne({private_token: appkey}).exec(callback)

//编译出来得app.js // Generated by CoffeeScript 1.6.3 var App, User, mongoose, schema;

mongoose = require(‘mongoose’);

User = require(‘./user’);

schema = new mongoose.Schema({ private_token: String, user_ids: Array, user_id: { type: mongoose.Schema.Types.ObjectId, ref: ‘User’ }, created_at: { type: Date, "default": Date.now }, updated_at: { type: Date, "default": Date.now }, name: String, uuid: String, welcome: String });

module.exports = mongoose.model('App’, schema);

App = module.exports; User = require(‘./user’);

module.exports.checkAppkey = function(appkey, callback) { App.findOne({ private_token: appkey }).exec(callback); };

回到顶部