mongoose = require 'mongoose'
class Locations
constructor: @(host, port) ->
@db = new mongoose 'locations', new Server(host, port, {auto_reconnect: true}, {})
this.db.open ->
null
getAll: (callback) ->
@db.collection 'locations', (err, locations_collection) ->
if err?
callback err
else
callback null, locations_collection
null
exports.Locations = Locations
我在一个名为locations.coffee
的文件中,在app.js
中,我有
locationsModel = require '../models/locations'
locationModel = new locationsModel 'localhost', 27017
但显然它永远不会被实例化,因为我得到了
node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
ReferenceError: host is not defined
答案 0 :(得分:1)
我之前没有看到使用Mongoose定义模型的方法。
您是否尝试过使用model definition guide?将它转换为Coffeescript应该相对容易。