【问题标题】:How to print a mongodb cursor?如何打印一个mongodb游标?
【发布时间】:2012-12-03 08:29:24
【问题描述】:
#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。

【问题讨论】:

    标签: mongodb coffeescript


    【解决方案1】:

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

    collection.find().each (err, item) -> console.log item if item
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-18
      • 1970-01-01
      • 2020-07-14
      • 1970-01-01
      • 1970-01-01
      • 2022-01-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多