Skip to content

error when overwriting query var #1992

Closed
@chaimsiegel

Description

@chaimsiegel

When I ran the following cloud code on parse-server I recieved the id of the first element twice ["VYSPEFBSx4", "VYSPEFBSx4"]

var data = ['7495176386', '8042291309'];
var query = new Parse.Query("Tick"); 
var results = [];
 data.forEach(function(num){
    query.equalTo("tickID", num);
    query.first().then(function(result){
        results.push(result.id);
    });
}); 

The response should be ["VYSPEFBSx4", "EBLarI2NA1"] however it appears that the parse query was not overwritten for the second element in the loop. (This error did NOT occur on Parse.)

I finally found the solution which is to declare the parse query in the forEach loop like:

var data = ['8042291309','7495176386'];
var results = [];
 data.forEach(function(num){
    var query = new Parse.Query("Tick"); 
    query.equalTo("tickID", num);
    query.first().then(function(result){
        results.push(result.id);
    });
}); 

I did not see any mention of this error in the migration guide and thought it might be helpful

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