最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - MongoDB Cursor has no method 'next' - Stack Overflow

programmeradmin1浏览0评论

These work fine:

myCollection.find();
myCollection.findOne();

This does not:

           myCollection.find().next();
                               ^
TypeError: Object #<Cursor> has no method 'next'

But documentation says:

cursor.next()

Returns: The next document in the cursor returned by the db.collection.find() method.

Any ideas on what I'm doing wrong?

These work fine:

myCollection.find();
myCollection.findOne();

This does not:

           myCollection.find().next();
                               ^
TypeError: Object #<Cursor> has no method 'next'

But documentation says:

cursor.next()

Returns: The next document in the cursor returned by the db.collection.find() method.

Any ideas on what I'm doing wrong?

Share Improve this question asked Jul 23, 2013 at 0:06 JapandroidJapandroid 231 silver badge4 bronze badges 2
  • 1 What is myCollection (how did you create it)? What mongodb driver do you use? Which version? Could you provide an SSCCE? – Zeta Commented Jul 23, 2013 at 0:19
  • There's a nextObject on the cursor in the MongoDB Node.JS driver: mongodb.github.io/node-mongodb-native/api-generated/…, but no next. – WiredPrairie Commented Jul 23, 2013 at 0:32
Add a ment  | 

2 Answers 2

Reset to default 5

While related, the JavaScript Methods in MongoDB are not the same as those in the native driver for Node.js.

The former, including cursor.next(), make up MongoDB's own API and are similar to SQL mands in relational databases. Use these when connected through the mongo shell.

The equivalent of cursor.next() within the Node.js driver API is cursor.nextObject().

Just to note that cursor.next() replaces nextObject() in 2.0 and is available.

发布评论

评论列表(0)

  1. 暂无评论