Start a new topic

Business Logic- searching for records in User table always empty


Im my business logic I am trying to get a user in the 'Users' table by using the collectionAccess module.

However, not matter what I try the results are always empty. (I still get the 'success' callback)

If I run the same queries on anything other than the 'Users' table, I get the expected records back.

Is there something wrong with my approach below ?

I know for a fact that there is a User that matches the query criteria. I even tried to search by '_id' and no luck.

var collectionAccess = modules.collectionAccess;

collectionAccess.collection('User').find({"first_name": "Doug"}, function (err, userColl) {

if (err) {

logger.error('Query failed: '+ err);

} else {

logger.error('Query success: '+ JSON.stringify(userColl));



Try lowercase 'user' - collectionAccess.collection('User').find(query, callback);
that was it, thanks a ton !

This is a common problem. I've asked it via email and answered it once or twice via the community forums. The confusion comes from the console. It shows "Users". Perhaps the Kinvey Console should show "Users (user collection)" for some hope of clarity?

Agreed that it's confusing, and we've been brainstorming solutions that would make it more clear. Besides the console renaming, one idea was to make 'aliases' such that getting collection User, user, Users or users would all return the right one. While this prevents you from actually having a separate collection with that name, this is not likely anyway, you are probably misunderstanding the built in feature and finally it would be confusing for you. Another option is to add a method modules.collectionAccess.userCollection() which returns the right one. Which one do you think is most intuitive?

Thanks for the response. You are right that many of the options introduce confusion and even some code overhead. The docs clearly show "user" collection. Examples:

* POST /user/:appKey/ HTTP/1.1

* var promise = Kinvey.User.signup({

* [KCSUser userWithUsername:@"kinvey" password:@"12345" withCompletionBlock:^(KCSUser *user, NSError *errorOrNil, KCSUserActionResult result) {

The problem is simply with the console. Since it shows "Users", developers like myself instantly think the collection is named "Users". Since I also name my collections with a capital and pluralized ( Invitations), I mistakenly think you do the same. Without referring to the docs, it's an easy mistake to make.

I think adding code to deal with misperceptions is just going to lead to nightmares down the road. I'd feel just changing the console to show "user Collection" is the most clear. It informs the developer of the correct name for the collection and is intuitive enough to show what you will received when you click on it. Maybe the "showing all users" description could also say "showing all users in the user collection"?

My 2 cents.
Login or Signup to post a comment