Fetch Multiple Documents with 1 key and multiple value

0 votes

Hi Guys,

  I'm trying to fetch multple document by using "FindDocumentByQuery" and tried to use the one with vector parameter. My goal is query document with different userID's. Is this possible?. I'm using cocos2d-x. Here's my code.

 

    std::vector<string> userIds;

    for(std::vector<FBUserData>::iterator it= pVect.begin(); it != pVect.end(); ++it)

    {

        FBUserData player = *it;

        string userID =  StringUtils::format("%llu",player.userID);

        userIds.push_back(userID);

    }

 

    Query *query = QueryBuilder::BuildQuery(KEY_USER_ID, userIds ,  APP42_OP_EQUALS);

    StorageService *storageService = App42API::BuildStorageService();

    storageService->FindDocumentByQuery(DB_NAME, COLLECTION_SCORES,query,app42callback(App42Utils::onStorageRequestQuery, this));

EDITED: Added screenshots link

http://pbrd.co/195spx0

http://pbrd.co/195sOiX

asked Mar 19, 2015 in App42 Cloud API-BaaS by blackmagicstd (16 points)
edited Mar 19, 2015 by blackmagicstd

1 Answer

0 votes

Hi,

Everything else seems ok in the above code snippet except the operator in the query.

Use APP42_OP_INLIST operator instead of APP42_OP_EQUALS then you will be able to get the desired result.

Let us know if you have further queries.

Thanks.

answered Mar 19, 2015 by rajeev.etc (1,660 points)
I've done that but I still got error, For now i have only 1 document on the table but still not working. It says: errordetails:No document in the collection 'Debug_Scores' exists for given query
errorMessage:Not Found
appErrorCode:2608
httpErrorCode:404

I also log my query which is : [{"key":"UserId","value":"[100004971962878,10205829683280456,556260764489277]","operator":"$in"}]

I will edit my post and try to post the screenshot of the table.
As you also see on the screenshot the user id "100004971962878" is there but I still got the error. I even tried a single push back and hardcoded the user id but still the same
The following code is working fine for me:

StorageService *storageService = App42API::BuildStorageService();
const char* dbName = "YOUR_DB_Name";
const char* collectionName = "YOUR_COLLECTION_Name";
const char* key = "age";
    
std::vector<std::string> value;
value.push_back("30");
value.push_back("40");
value.push_back("41");

Query *query = QueryBuilder::BuildQuery(key, value, APP42_OP_INLIST);
    
storageService->FindDocumentByQuery(dbName, collectionName,query,app42callback(TestStorageService::onStorageRequestCompleted, this));

Can you try calling FindAllDocuments API and see the response?
Also can you cross-check if the issue is coming due to collection name mismatch.

It will be really helpful if you can share your API_KEY, SECRET_KEY, DB_NAME and COLLECTION_Name to find out the problem.

Please send the above details on support@shephertz.com, also mention this post url in the mail.
Hi, I sent it on the given e-mail hope I can get a reply as soon as possible , been stuck on this. Also I even double check if names are mismatch but it's not, I even tried hardcoded it and copy paste what's on the app42 console. I even tried your code on my test code and collection and it doesn't work. On your code I expect to get all documents with that different age but I got the same error, same with my problem :(
Hi,
There was a bug in the older version of the SDK that we have solved it now and updated the sdk which can be downloaded from our github repo( https://github.com/shephertz/App42_Cocos2DX_SDK/tree/master/V_1.9.1/App42 ).

Let us know if you have further questions.
Thanks.
Thanks, I just have another question. It is possible to do a function like a "Saving additional Data along with Score From Facebook" and "Fetch Additional data in leaderbaord From Facebook". In short I want the extra data to be tie in to the facebook friends or user ids. Is that possible?
Yes, you can save additional data along with the score, but you have to fetch the facebook details first and then add those details while saving the score.

We have a good discussion over here( http://forum.shephertz.com/?qa=5488/getting-user-name-of-gettopnrankers-response-is-facebook-id ) on the same use case.
Thanks I've read the discussion but using "GetTopNRankers" will fetch all scores even there not your friends so It's not tie in anymore on your facebook friends right?
There is an API "GetTopNRankersFromFacebook( http://api.shephertz.com/app42-docs/leaderboard-service/?sdk=cocos2dx#get-top-n-rankers-from-facebook )" that give you score of your facebook friends.

The only precaution is while saving the score you should pass fbid as userName in SaveUserScoe API.
I guess I just have to wait for an API that's like "Edit score with extra data From Facebook" because right now you can only edit score and with the extra data on it. You have to call another extra API just to do it.It would be also helpful if there's an API that only save the highest score from the user because saving it locally will not be helpful because there's a chance that the user will delete his/her local storage and different scenario can occur that can mess up your database if you sync the scores again. Anyway thanks for the answers.
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...