As of April 12th, you must go to Progress SupportLink to create new support cases or to access existing cases. Please, bookmark the SupportLink URL and use the new portal to contact the support team.
How to efficiently fetch entities defined by list of ids?
D
Daniel
started a topic
over 8 years ago
I have a list of ids stored in array. I want to fetch entities with those ids. I can not see how to use the inline or nested or() operator in a for loop.
Your documentation reads:
The example below demonstrates how to join two separate queries.
var query =newKinvey.Query();query.equalTo('last_name','Doe');var secondQuery =newKinvey.Query();secondQuery.equalTo('last_name','Roe')// Selects all users with last_name “Doe” or “Roe”.query.or(secondQuery);
Alternatively, the snippet above can be shortened using the join operator inline.
// Selects all users with last_name “Doe” or “Roe”.var query =newKinvey.Query();query.equalTo('last_name','Doe').or().equalTo('last_name','Roe');
Best Answer
P
Pranav J
said
over 7 years ago
Hey Daniel,
I am able to implement your scenario using ternary operator.
See if the below snippet helps.
var names = ["Doe","Roe"]; var finalQuery; for (var i =0; i < names.length; i++){ var q = new Kinvey.Query().equalTo('name',names[i]); finalQuery = (finalQuery) ? finalQuery.or(q) : q; }
I'm not entirely certain that I understand your question. Both of the queries listed would be effective to do what they said they would do and give fairly clear examples on how to use them. Can you give me an example in which you would need to use a query in a for loop as my answer right now is going to be rather unhelpful without knowing more.
Thanks,
D
Daniel
said
over 8 years ago
Simply I do not understand how the or() works. It returns the instance of query, yes? Can I do this?
var query = new Kinvey.Query();
for (...) {
query.equalTo('_id', list[i]).or();
}
Is it ok that with the Iast iteration I call the or() method without adding another Query?
P
Pranav J
said
over 7 years ago
Answer
Hey Daniel,
I am able to implement your scenario using ternary operator.
See if the below snippet helps.
var names = ["Doe","Roe"]; var finalQuery; for (var i =0; i < names.length; i++){ var q = new Kinvey.Query().equalTo('name',names[i]); finalQuery = (finalQuery) ? finalQuery.or(q) : q; }
Daniel
I have a list of ids stored in array. I want to fetch entities with those ids. I can not see how to use the inline or nested or() operator in a for loop.
Your documentation reads:
The example below demonstrates how to join two separate queries.
Alternatively, the snippet above can be shortened using the join operator inline.
Hey Daniel,
I am able to implement your scenario using ternary operator.
See if the below snippet helps.
var names = ["Doe","Roe"];
var finalQuery;
for (var i =0; i < names.length; i++){
var q = new Kinvey.Query().equalTo('name',names[i]);
finalQuery = (finalQuery) ? finalQuery.or(q) : q;
}
var promise = Kinvey.DataStore.find('collection-name', finalQuery);
promise.then(function(response) {
...
}, function(error) {
...
});
Also a query like "new Kinvey.Query().equalTo('name','Doe').or()" would fetch all the entities.
Thanks,
Pranav
Kinvey Support
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstDamien Bell
Daniel,
I'm not entirely certain that I understand your question. Both of the queries listed would be effective to do what they said they would do and give fairly clear examples on how to use them. Can you give me an example in which you would need to use a query in a for loop as my answer right now is going to be rather unhelpful without knowing more.
Thanks,
Daniel
Simply I do not understand how the or() works. It returns the instance of query, yes? Can I do this?
var query = new Kinvey.Query();
for (...) {
query.equalTo('_id', list[i]).or();
}
Is it ok that with the Iast iteration I call the or() method without adding another Query?
Pranav J
Hey Daniel,
I am able to implement your scenario using ternary operator.
See if the below snippet helps.
var names = ["Doe","Roe"];
var finalQuery;
for (var i =0; i < names.length; i++){
var q = new Kinvey.Query().equalTo('name',names[i]);
finalQuery = (finalQuery) ? finalQuery.or(q) : q;
}
var promise = Kinvey.DataStore.find('collection-name', finalQuery);
promise.then(function(response) {
...
}, function(error) {
...
});
Also a query like "new Kinvey.Query().equalTo('name','Doe').or()" would fetch all the entities.
Thanks,
Pranav
Kinvey Support
-
How do I use Kinvey in my web app?
-
Is it safe to include keys/secrets in my client-side JavaScript app?
-
Why is the activeUser null even though I am logged in?
-
Login does not work even though credentials are valid.
-
Social login doesn’t work.
-
Appending objects to an Array (HTML5 - JS)
-
New to node.js - need bootstrap to downloadfiles from Kinvey
-
Problem with Aggregation/Grouping
-
Internal Server Error using Twitter Sign Up
-
Data Store
See all 315 topics