Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Can';t在CoffeeScript中使用MongoDB、Mongoose、Node.js和Express显示数据_Mongodb_Node.js_Coffeescript_Express_Mongoose - Fatal编程技术网

Can';t在CoffeeScript中使用MongoDB、Mongoose、Node.js和Express显示数据

Can';t在CoffeeScript中使用MongoDB、Mongoose、Node.js和Express显示数据,mongodb,node.js,coffeescript,express,mongoose,Mongodb,Node.js,Coffeescript,Express,Mongoose,我有一个Node.js,用CoffeeScript编写的带有Mongo和Mongoose的Express设置 我可以使用以下代码将数据保存到我的集合中: # new app.get "/admin/new", (req, res) -> res.render "admin/new.jade", locals: c: new Content() # create app.post "/admin.:format?", (req, res) -> content = new

我有一个Node.js,用CoffeeScript编写的带有Mongo和Mongoose的Express设置

我可以使用以下代码将数据保存到我的集合中:

# new
app.get "/admin/new", (req, res) ->
  res.render "admin/new.jade", locals: c: new Content()

# create
app.post "/admin.:format?", (req, res) ->
    content = new Content(req.body["content"])
    content.save ->
        switch req.params.format
            when "json"
                res.send content.__doc
            else
                res.redirect "/"
但是我不能用这个代码显示任何数据。web浏览器只是说“等待本地主机…”,而控制台什么也没说

# index
app.get "/admin.:format?", (req, res) ->
    Content.find().all (contents) ->
        switch req.params.format
            when "json"
                res.send contents.map((c) ->
                    c.__doc
                )
            else
                res.render "admin/index.jade", locals: contents: contents

我正在看Moongoose文档

如果不指定回调,则可以使用进一步优化搜索,而查询对象似乎没有指定“all”函数。您的代码是否正在悄无声息地失败

我相信你真正想要的是:

Content.find({}).exec (err, contents) ->

谢谢,现在很好!发现了。所有这些都在一个教程中,可能是一个旧教程。在更新中遇到了更多问题,我在这里提出了另一个问题: