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
我想我现在的问题是将所有内容放入哪些文件。 – Shamoon