Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MongoDB不查询_C#_Xcode_Mongodb_Facebook_Unity3d - Fatal编程技术网

C# MongoDB不查询

C# MongoDB不查询,c#,xcode,mongodb,facebook,unity3d,C#,Xcode,Mongodb,Facebook,Unity3d,嗨,我正试图通过使用Facebook ID列表作为参数来查询我的Mongo数据库,以便返回具有相应帐户的用户列表。该方法在Unity编辑器中运行良好,但是当我在iOS上运行它时,我得到一个构造函数错误(我设置了一个空白的默认构造函数以解决这个问题,但是它仍然不工作) 初始方法 public void FetchData() { //data = Mongo.Instance.players.FindAll().ToList(); if (FB.IsLog

嗨,我正试图通过使用Facebook ID列表作为参数来查询我的Mongo数据库,以便返回具有相应帐户的用户列表。该方法在Unity编辑器中运行良好,但是当我在iOS上运行它时,我得到一个构造函数错误(我设置了一个空白的默认构造函数以解决这个问题,但是它仍然不工作)

初始方法

 public void FetchData()
    {
        //data = Mongo.Instance.players.FindAll().ToList();
        if (FB.IsLoggedIn)
        {
            FB.API("me/friends", HttpMethod.GET, FriendsHighscoreHndlr);
        }
    }
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();
        }
private string getDataValueForKey(Dictionary<string, object> dict, string key) {
            object objectForKey;
            if (dict.TryGetValue(key, out objectForKey)) {
                return (string)objectForKey;
            } else {
                return "";
            }
        }
回调方法

 public void FetchData()
    {
        //data = Mongo.Instance.players.FindAll().ToList();
        if (FB.IsLoggedIn)
        {
            FB.API("me/friends", HttpMethod.GET, FriendsHighscoreHndlr);
        }
    }
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();
        }
private string getDataValueForKey(Dictionary<string, object> dict, string key) {
            object objectForKey;
            if (dict.TryGetValue(key, out objectForKey)) {
                return (string)objectForKey;
            } else {
                return "";
            }
        }

您是否尝试过使用Mongo的.NET驱动程序中的筛选器

我建议尝试下面的例子。(注意:此事件是在定义为集合的预定义对象上激发的。)

var filter=Builders.filter.Eq(obj=>obj.attribute,List);

您是否可以添加一个您希望查询返回的文档?另外,请为
FBresult
@Veeram添加输入值,我添加了编辑手链。尝试在不使用任何筛选器的情况下查询数据库,并查看是否得到任何结果(这将确认您正在查询正确的数据库/集合)。运行上述代码时,您会得到什么响应?在代码中记录值时,是否看到正确的
fbids
?您能否共享并验证将正确的输入值
IGraphResult FBresult
传递给方法
FriendshighCorehndlr
?您是否尝试过直接创建
friendIDsFromFB
列表,以排除第一阶段的任何格式/转换或其他问题?您的
查询方法为什么有缺陷?你期望什么样的产出,你得到什么?请提供更多信息。另外,您使用的是哪个版本的Bson?