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

These work fine:myCollection.find();myCollection.findOne();This does not:myCollection.find().next();^

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745223296a4617347.html

相关推荐

  • javascript - MongoDB Cursor has no method &#39;next&#39; - Stack Overflow

    These work fine:myCollection.find();myCollection.findOne();This does not:myCollection.find().next();^

    5小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信