简体   繁体   中英

Get specific object from Parse (.com) query result by field without going back to DB

So say I do a query on Parse database and get a results object, with each result having a field place_id .

How can I then get a specific object by place_id from the results without actually going back to the database (want to minimise network traffic and db querying...)?

This is what my query will look like:

var LatestUpdate = Parse.Object.extend("LatestUpdate");
var query = new Parse.Query(LatestUpdate);
query.containedIn("place_id", arrayOfplaceIds);
query.find().then(
  function(results){
    // and then i want to do something like:
    return results.findByField("place_id", 1234) // get a specific object from the result without going back to the database?
  }
);

You have to loop through your results and find the object that matches your criteria. You can do this easily using underscore.js which is supported on the cloud:

var match = _.find(results, function(object){ return object.get("place_id") == 1234; });

Just make sure your have var _ = require('underscore'); on top of your js file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM