Skip to content

How many can i get result with query.each ? (maximum size) #6248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
memishood opened this issue Dec 1, 2019 · 6 comments
Closed

How many can i get result with query.each ? (maximum size) #6248

memishood opened this issue Dec 1, 2019 · 6 comments

Comments

@memishood
Copy link

i m using parse jobs on cloud code:

Parse.Cloud.job('Purchase', (req,status) => {

	var query = new Parse.Query('Subscriptions');
	query.find({useMasterKey: true}).then(()=>{
		query.each((result,err) => {
			let userId = result.get('userId');
			var _query = new Parse.Query(Parse.User);
			_query.equalTo('objectId', userId);
			_query.first({useMasterKey: true}).then((user => {
				let date = result.get('end');
				let current = new Date();
				user.set('isGold', (date > current));
				user.save(null,{useMasterKey: true});
			}));
		});
	}).catch(e => console.log(e));

});

if I have more than 100,000 results in Subscriptions class, does it work for all result ? (query.limit(int) doesn't work with query.each, i tried.)

@davimacedo
Copy link
Member

Please, use stackoverflow for code related questions. Anyway, the code below should solve your problem:

Parse.Cloud.job('Purchase', (req,status) => {
	var query = new Parse.Query('Subscriptions');
	query.each(result => {
			let userId = result.get('userId');
			var _query = new Parse.Query(Parse.User);
			_query.equalTo('objectId', userId);
			_query.first({useMasterKey: true}).then((user => {
				let date = result.get('end');
				let current = new Date();
				user.set('isGold', (date > current));
				user.save(null,{useMasterKey: true});
			}));
	}, {useMasterKey: true});
});

@memishood
Copy link
Author

@davimacedo my code is working perfectly i just asked if the parse class have more than 100k row, will it work again perfectly?

@davimacedo
Copy link
Member

Your code is wrong. You are using the each function inside the find block. That's not the way it should be used. There is no limit for the each function if you use it correctly. It will do as many find operations are required to make sure that all objects will be returned.

@memishood
Copy link
Author

memishood commented Dec 3, 2019

@davimacedo thx, i had got it from back4app docs :))) https://www.back4app.com/docs/free-cron-job-online

@davimacedo
Copy link
Member

@memishood thanks for reporting. The example is slightly different because they first used the find method to show how many objects will be destroyed. They should had used the count though and I will make sure they will update it. In your case, since you are not using the result of the find operation, you can go just with the each.

@memishood
Copy link
Author

@davimacedo thx sir

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants