2011-10-13 3 views
1

CoffeeScript로 작성된 Mongo 및 Mongoose로 Node.js, Express 설치가 있습니다.CoffeeScript로 MongoDB, Mongoose, Node.js 및 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 "/" 

하지만이 코드와 데이터를 표시 할 수 없습니다. 웹 브라우저에는 "Waiting for localhost ..."라고 표시되고 콘솔에는 아무것도 표시되지 않습니다.

# 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 

답변

3

Moongoose 설명서를 살펴 보겠습니다.

querying documentation은 콜백을 지정하지 않으면 Query object을 사용하여 검색을 더욱 세분화 할 수 있으며 쿼리 개체가 "all"기능을 지정하지 않는 것으로 나타납니다. 코드가 자동으로 실패합니까?

나는 당신이 정말 찾고있는 것은 생각 :

+0

감사합니다, 이제 괜찮 workes! 그것을 튜토리얼에서 발견했습니다. 아마도 오래된 것입니다. – Alfred

+0

업데이트와 관련하여 더 많은 문제가 있으니 여기서 또 다른 질문을 던졌습니다 : http://stackoverflow.com/questions/7760838/cannot-post-with-node-js-express-mongodb-mongoose-coffeescript – Alfred

관련 문제