2011-09-14 27 views
3
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,我有使用MongoDB在Node.js中定义`model`的正确方法是什么?

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 

回答

1

我从来没见过这种方法之前使用Mongoose定义模型。

您是否尝试过使用它们的model definition guide?将其转换为Coffeescript应该相对容易。

+0

我想我现在的问题是将所有内容放入哪些文件。 – Shamoon

相关问题