为什么mongoose model找不到方法
发布于 11 年前 作者 sanvibyfish 5501 次浏览 最后一次编辑是 8 年前

我调用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); };

回到顶部