
[英]MongoDB : in a forEach cursor, how to print found filtered documents?
[英]How to print a mongodb cursor?
#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游标不是数组,因此您应该在倒数第二行中使用如下代码:
collection.find().each (err, item) -> console.log item if item
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.