Start a new topic
Answered

How to query to get data from multiple collections.

Hi, 
We have two collections Collection A, Collection B which contain related data. I want to have a single query through which I can retrieve data from both collections (all data or few necessary data). 
Is it possible? 


Please let me know any link that could help about relational data handling. Sample would be appreciated. 


Thank you in advance.


Best Answer
Anu,

We've been encouraging customers away from relational models when possible as we're backed by Mongo which itself is non-relational. Relational data support is deprecated at this point. If you need to do references you can build your own in Business Logic https://devcenter.kinvey.com/android/guides/business-logic#


Kinvey is backed by Mongo which does not support relationships out of the box. Instead, we encourage developers to denormalize their data. Our scale makes it so it doesn't matter how many rows or columns you store in each collection.


Our engineering team put together an article to help folks understand how we think about data on NoSQL: https://devcenter.kinvey.com/android/guides/data-modeling# I'd recommend reading this.


Thanks,

Pranav

 


Answer
Anu,

We've been encouraging customers away from relational models when possible as we're backed by Mongo which itself is non-relational. Relational data support is deprecated at this point. If you need to do references you can build your own in Business Logic https://devcenter.kinvey.com/android/guides/business-logic#


Kinvey is backed by Mongo which does not support relationships out of the box. Instead, we encourage developers to denormalize their data. Our scale makes it so it doesn't matter how many rows or columns you store in each collection.


Our engineering team put together an article to help folks understand how we think about data on NoSQL: https://devcenter.kinvey.com/android/guides/data-modeling# I'd recommend reading this.


Thanks,

Pranav

 

Hi Pranav,


Thanks for your reply.

I am using the approach you have suggested through Business Logic and created a collection hook on console with my two collections, but not getting how to request and get response in the android application.

Would you please tell me how to use collection hooks in Kinvey for Android?

Thanks Pranav for the info.

But I still could not make out how we will send request body with the find() of the datastore and how we will get the data of both collections through response.


Suppose, I have written a business logic onPostFetch() collection hook on a collection 'employee' and it is getting executed fine on the console but how I can utilize this in our android code.

If I m trying to call a find() method on employee datastore from android code it gives empty list in onSuccess() method of callback.


Android code:


DataStore empDataStore = DataStore.collection("employee",Employee.class, StoreType.SYNC,mKinveyClient);
private void findData(){

empDataStore.find(mKinveyClient.query(), new KinveyListCallback<Employee>() {

@Override
public void onSuccess(List<Employee> list) {

Log.e(TAG,"Size : "+list.size());

if(!list.isEmpty()) {
Log.e(TAG, list.get(0).getName());
}

}

@Override
public void onFailure(Throwable throwable) {

}
});

} Business logic output on console is :
{ "things": [ { "_id": "59b23f6c68c53f4a045eac6f", "department": "59b0d96eacf2295604390afe", "departmentRef": { "_collection": "Department", "_id": "59b0d96eacf2295604390afe", "_type": "KinveyRef" }, "designation": "Associate", "name": "Mahesh", "_acl": { "creator": "59acfc14e884417c04e1939d" }, "_kmd": { "lmt": "2017-09-08T06:58:02.245Z", "ect": "2017-09-08T06:57:48.733Z" } } ], "stuff": [ { "_id": "59b0d96eacf2295604390afe", "deptName": "Finance", "_acl": { "creator": "59acfc14e884417c04e1939d" }, "_kmd": { "lmt": "2017-09-08T07:05:40.575Z", "ect": "2017-09-08T06:50:18.680Z" } } ]

Anu,

Looks like you are not constructing the query on client side. Please take a look at 'fetch multiple entities using a query' on this link.

Also, provide me with the query that you tried on API console for which you are getting business logic output successfully.

Thanks,
Pranav

 

Login or Signup to post a comment