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.'

このコレクションの内容を、nodejslocalhostサーバーで実行されているmongoデータベースのコンソールに出力しようとしています。最初と最後のconsole.logは正常に表示されますが、カーソル自体は表示されません。そして、エラーはスローされません。何か案は?上記はCoffeeScriptです。

4

1 に答える 1

1

MongoDB カーソルは配列ではないため、2 行目から最後の行では代わりに次のようなものを使用する必要があります。

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