简体   繁体   English

MongoDB没有查询

[英]MongoDB not querying

Hi I am trying to query my Mongo Database by using a list of Facebook ID's as the parameter in order to return the list of users with corresponding accounts. 嗨,我试图通过使用Facebook ID列表作为参数来查询我的Mongo数据库,以便返回具有相应帐户的用户列表。 The method works fine in the Unity Editor however when I run it on iOS I get a constructor error (I have set a blank default constructor in order to solve the issue however it still doesn't work) 该方法在Unity编辑器中工作正常,但是当我在iOS上运行时,我得到一个构造函数错误(我已经设置了一个空白的默认构造函数以解决问题,但它仍然无效)

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 "";
            }
        }

Return Query Result 返回查询结果

{
    "_id" : ObjectId("XXXXXX"),
    "facebookID" : "XXXXXXXXXXXXXX",
    "name" : "John Doe",
    "highScore" : 40501
}

Have you tried using a filter from Mongo's .NET drivers? 您是否尝试过使用Mongo .NET驱动程序的过滤器?

I would suggest trying something like the example below. 我建议尝试类似下面的例子。 (Note: this event is being fired on a pre-defined object which is being defined as a collection.) (注意:此事件是在定义为集合的预定义对象上触发的。)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM