MongoDB does not request

Hey. I am trying to query my Mongo database using a list of Facebook IDs as a parameter to return a list of users with matching accounts. The method works fine in the Unity editor, but when I run it on iOS, I get a constructor error (I installed an empty default constructor to solve the problem, however it still doesn't work)

Initial method

 public void FetchData()
    {
        //data = Mongo.Instance.players.FindAll().ToList();
        if (FB.IsLoggedIn)
        {
            FB.API("me/friends", HttpMethod.GET, FriendsHighscoreHndlr);
        }
    }

Callback method

public void FriendsHighscoreHndlr (IGraphResult FBresult){            
            var dict = Json.Deserialize(FBresult.ToString()) as Dictionary<string,object>;
            var friendList = new List<object>();
            friendList = (List<object>)(dict["data"]);

            int _friendCount = friendList.Count;
            Debug.Log("Found friends on FB, _friendCount ... " +_friendCount);
            List<string> friendIDsFromFB = new List<string>();
            for (int i=0; i<_friendCount; i++) {
                string friendFBID = getDataValueForKey( (Dictionary<string,object>)(friendList[i]), "id");
                string friendName =    getDataValueForKey( (Dictionary<string,object>)(friendList[i]), "name");
                Debug.Log( i +"/" +_friendCount +" " +friendFBID +" " +friendName);
                friendIDsFromFB.Add(friendFBID);
            }
            //friendIDsFromFB.Add(AccessToken.CurrentAccessToken.UserId);
            var query = Query.In("facebookID", BsonArray.Create(friendIDsFromFB));
            //Debug.Log(query);
            data = Mongo.Instance.players.Find(query).ToList();
        }

Data Value for Key Method

private string getDataValueForKey(Dictionary<string, object> dict, string key) {
            object objectForKey;
            if (dict.TryGetValue(key, out objectForKey)) {
                return (string)objectForKey;
            } else {
                return "";
            }
        }

Request Return Result

{
    "_id" : ObjectId("XXXXXX"),
    "facebookID" : "XXXXXXXXXXXXXX",
    "name" : "John Doe",
    "highScore" : 40501
}
+4
source share
1 answer

Have you tried using the filter from the Mongo.NET drivers?

- . (: , .)

        var filter = Builders<Object>.Filter.Eq(obj => obj.attribute, List<IDs>);
+4

Source: https://habr.com/ru/post/1677947/


All Articles