0
#Database Testing Method.
            socket.on 'databaseTesting', ->
                db.collection 'documents', (err, collection) ->
                    console.log 'Printing documents...'
                    console.log cursor.item for cursor in collection.find() when cursor.hasNext isnt false 
                    console.log 'Documents printed.'

我正在尝试将此集合的内容打印到在 nodejs localhost 服务器上运行的 mongo 数据库的控制台。第一个和最后一个 console.log 显示正常,但不是光标本身。并且不会抛出任何错误。有任何想法吗?以上是 CoffeeScript。

4

1 回答 1

1

MongoDB 游标不是数组,因此您应该在倒数第二行使用类似的内容:

collection.find().each (err, item) -> console.log item if item
于 2012-12-15T16:47:53.973 回答