mongodb - hasNext not working on collection in javascript - Stack Overflow

I have following code in javascript which retrieves two rows:var raceCursor = RacesCollection.find({eve

I have following code in javascript which retrieves two rows:

 var raceCursor = RacesCollection.find({eventId: "e1"});
    var race;
    while(raceCursor.hasNext()){
    race = raceCursor.next();                   
    console.log(race.raceName);
    }

Seems nothing wrong with it, but it shows :

Uncaught TypeError: Object [object Object] has no method 'hasNext' in the javascript console.

What I am missing here?

Do the MongoDB methods requires special imports in javascript, in order to be used on the collections??

The Collection is:

RacesCollection  = new Meteor.Collection("RacesCollection");
RacesCollection.insert({raceId:"r1", eventId:"e1", raceName:"Moto race 1", status:"statusDetail"});
RacesCollection.insert({raceId:"r2", eventId:"e1", raceName:"Moto race 2", status:"statusDetail"});

Any remendation will be appriciated. thanks..

I have following code in javascript which retrieves two rows:

 var raceCursor = RacesCollection.find({eventId: "e1"});
    var race;
    while(raceCursor.hasNext()){
    race = raceCursor.next();                   
    console.log(race.raceName);
    }

Seems nothing wrong with it, but it shows :

Uncaught TypeError: Object [object Object] has no method 'hasNext' in the javascript console.

What I am missing here?

Do the MongoDB methods requires special imports in javascript, in order to be used on the collections??

The Collection is:

RacesCollection  = new Meteor.Collection("RacesCollection");
RacesCollection.insert({raceId:"r1", eventId:"e1", raceName:"Moto race 1", status:"statusDetail"});
RacesCollection.insert({raceId:"r2", eventId:"e1", raceName:"Moto race 2", status:"statusDetail"});

Any remendation will be appriciated. thanks..

Share Improve this question edited Oct 19, 2012 at 8:07 Mario S 12k24 gold badges41 silver badges47 bronze badges asked Oct 19, 2012 at 7:42 sohel khalifasohel khalifa 5,5883 gold badges36 silver badges46 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

According to Meteor docs the proper way to iterate a cursor is cursor.forEach(). Also cursors don't have hasNext() or next() methods.

So in your case it should read:

var raceCursor = RacesCollection.find({eventId: "e1"});

raceCursor.forEach(function(race) {
    console.log(race.raceName);    
});

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

相关推荐

  • mongodb - hasNext not working on collection in javascript - Stack Overflow

    I have following code in javascript which retrieves two rows:var raceCursor = RacesCollection.find({eve

    15小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信