Start a new topic
Answered

Make a query for all users with iOS SDK swift 3?

Hello everyone!

I'm new to Kinvey and would like to know how to perform a query to get all available users from the "users" collection.

PS: I need to know for other users to send evaluations or information.


I've tried the following:

1.  if let user = Kinvey.sharedClient.activeUser {

     let userQuery = UserQuery()

     userQuery.userId = nil

     user.lookup(userQuery){ (usersKV, error) in

         if let usersKV = usersKV {

             //success

             print("Users: \(usersKV)")

             self.users = usersKV

         } else {

             print(error!)

             //fail

         }

     }


  }


this throws me an error: unknownJsonError



2. let dataStoreUsers = DataStore<User>.collection()

   

   dataStoreUsers.find() { usersKV, error in

       if let usersKV = usersKV {

       //succeed

           print("Users: \(usersKV)")

           self.users = usersKV

       } else {

           print("error: \(error!)")

           //fail

       }

   }


this throws me an error in DataStore<User>.collection(): Type 'User' does not conform to protocol 'Persistable'


Best Answer

Rodrigo,


Did you get a chance to review Billy's earlier comment?


Secondly, in your code, if you lookup the user providing an email address, does that work for you?

Here is how the query will look like:


 

let userQuery = UserQuery {
        $0.email = "james.bond@mi6.com"
    }

 


Also, you can create your tickets on the support portal as you are a paying customer. Kinvey forum is for free customers.

https://support.kinvey.com/support/tickets/new


Thanks,

Pranav

Kinvey Support


Rodrigo,


What is the Kinvey SDK version that you are using?


Check following link for the latest SDK

http://devcenter.kinvey.com/ios/downloads#


Thanks,

Pranav

Kinvey Support

the version is 3.3.4


PD: 

the query that I made in number 1 was:

1.  if let user = Kinvey.sharedClient.activeUser {

     let userQuery = UserQuery()

     user.lookup(userQuery){ (usersKV, error) in

         if let usersKV = usersKV {

             //success

             print("Users: \(usersKV)")

             self.users = usersKV

         } else {

             print(error!)

             //fail

         }

     }

 

  }


this throws me an error: unknownJsonError

the version is 3.3.4 with cocoapod


PD: in query 1, the 3th line userQuery.userId = nil not apply. This line is commented

Hello Rodrigo,


Kinvey does not all the app to query the Users collection for all users. This would be a security risk.


Can you tell us about your use case and why you are trying to do this from the app.


Regards,


Billy

The purpose of the app is to perform a performance evaluation of other users as well as themselves. For that, I would like to make a query to the users table. Then, I would like to select one of them from the above mentioned query and perform the evaluation, registering the evaluation in a collection called "Evaluation" that should have the user evaluator (activeUser), the user to evaluate (Obtained from the query To the collection "users"), and other extra data.

Hello Rodrigo,


Thank you for your quick reply.


Let me repeat your use case in another way to make sure that I understand. You want an app user to be able to get a list of all other app users (using the aforementioned all-user query). Then you want the app user to select any one of the users from the list of Kinvey Users and perform an evaluation on them and then send the evaluation to Kinvey to be stored in a different collection, is that correct?


Will the "Evaluator" user have a requirement to modify the Kinvey User record for the "Evaluated" user in any way.


We would like to know the name of this app and the KID for the environment that you are working in, however we don't want you to post it in this Forum. Can you please send it to billy@kinvey.com so that it is kept private?


Someone will take a closer look at your above queries and errors as soon as you respond with the specific KID and environment name.


Regards,


Billy Gee



Answer

Rodrigo,


Did you get a chance to review Billy's earlier comment?


Secondly, in your code, if you lookup the user providing an email address, does that work for you?

Here is how the query will look like:


 

let userQuery = UserQuery {
        $0.email = "james.bond@mi6.com"
    }

 


Also, you can create your tickets on the support portal as you are a paying customer. Kinvey forum is for free customers.

https://support.kinvey.com/support/tickets/new


Thanks,

Pranav

Kinvey Support

thanks for reply. Finally I used business logic (Custom Endpoint) for my query. 

KID is kid_B1RFK021l and the name of app is "Desempeño".  


Also, I made some changes to the model so I didn't have to ask directly to the users table.


thanks very much.

Login or Signup to post a comment