hasNext not working on collection in javascript
javascript, meteor, mongodb
Solution
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);
});
Problem
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 recommendation will be appriciated. thanks..