Skip to content

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

Closed

Description

@memishood

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.)

Activity

  1. davimacedo commented on Dec 2, 2019

    @davimacedo
    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});
    });
  2. memishood commented on Dec 2, 2019

    @memishood
    Author

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

  3. davimacedo commented on Dec 2, 2019

    @davimacedo
    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.

  4. memishood commented on Dec 3, 2019

    @memishood
    Author

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

  5. davimacedo commented on Dec 3, 2019

    @davimacedo
    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.

  6. memishood commented on Dec 3, 2019

    @memishood
    Author

    @davimacedo thx sir

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions