Meteor js cursor hasNext() and next()?


I have a potentially big find query which has to stop once my server "javascript" conditions are met, for instance my server already have documents results to figure out a solution.

The idea here is to iterate a cursor from mongo, hitting mongo "on demand", kinda "streaming", so neither my server or mongo has to fetch all results at once.

expected behaviour

query and get cursor ( r = Collection.find() )
check for next ( r.hasNext() )
fetch next ( )
once my requirements are met, stop ( delete r )

example code

Collection.find().forEach(function(doc) {
doc = do_my_business( doc );
if (doc.found) {
// hey mister cursor, go home and die! don't touch my mongo anymore!
return false;

the real problem

I created another Question which is actually how i end up here:
Mongodb find near until $maxDistance or at least X records?


A meteor cursor isn't a mongo cursor. Meteor cursors don't have hasNext or next. So, this is really just a question about forEach, which is the same as the ES5 forEach. So here's what you can do:

1.Fetch all the docs into an array & run a for loop over it, break when criteria is met.

2.Turn a flag when the criteria is met & check at the beginning of the function:

if (isHappy) return;
doc = do_my_business( doc );
if (doc.found) isHappy = true;

3. Use a try catch loop:

foo = {};
try {
Collection.find().forEach(function(doc) {
doc = do_my_business( doc );
if (doc.found) {
throw foo;
} catch(e) {
if (e !== foo) {
throw e;

4.Forget the forEach garbage & use a $where with a findOne + (do a find().limit(1).explain() so you can see that it won't touch every document.)

5.Store something in your database so you don't have to use javascript on the cursor. Repeating a javascript loop over every doc on the server should be avoided like the plague. Storage is cheap. processing, not so much.

how to implement progress bar using angular js for processing multiple request?

I have created multiple orders and now I have to confirm all these
orders but until and unless all orders gets confirmed I have to show
progress bar and have to show the status of the ordered confirmed

i.e. suppose i have confirmed 10 orders then 1/10 then 2/10 then 3/10
...10/10 status of orders getting confirmed at background.

below i have one example but which doesn't meets to requirement ..

angular.module("app", []) .controller("main", ['$scope',
function($scope) {
$scope.value = 10
$scope.items = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100] }]) .directive('progressbar', [function() {
return {
restrict: 'A',
scope: {
'progress': '=progressbar'
controller: function($scope, $element, $attrs) {
value: $scope.progress

$scope.$watch(function() {
$element.progressbar({value: $scope.progress})
} }])


I have once used below template:

You can use it:

SMTP error code : 551

com.sun.mail.smtp.SMTPSendFailedException: 551 This mail server requires authentication before sending mail from a locally hosted domain. Please reconfigure your mail client to authenticate before sending mail.

I am getting the error above when I integrate with the my Java Application running on a Tomcat server

Sending successfully if I use the same properties in separate class with main and run as java application

Why I am not getting this? Thank you in advance.


Finally got answer
Here we go: before it was like
`Properties props = new Properties();
props.put("", "");
props.put("mail.smtp.port", "25");
props.put("mail.smtp.starttls.enable", true);
props.put("mail.smtp.auth", true);`

now i changed to:
`Properties props = new Properties();
props.setProperty("", "");
props.setProperty("mail.smtp.port", "25");
props.setProperty("mail.smtp.starttls.enable", "true");
props.setProperty("mail.smtp.auth", "true");`