MongoDB没有在iOS Unity Build上运行

时间:2017-06-01 02:51:11

标签: c# ios xcode mongodb unity3d

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

错误

MissingMethodException: Method not found: 'Default constructor not found...ctor() of MongoDB.Driver.CommandResultSerializer'.
  at System.Activator.CreateInstance (System.Type type, System.Object[] args) [0x00000] in <filename unknown>:0 
  at MongoDB.Bson.Serialization.Attributes.BsonSerializerAttribute.CreateSerializer (System.Type type) [0x00000] in <filename unknown>:0 
  at MongoDB.Bson.Serialization.BsonSerializer.LookupSerializer (System.Type type) [0x00000] in <filename unknown>:0 
  at MongoDB.Driver.MongoServerInstance.RunCommandAs[TCommandResult] (MongoDB.Driver.Internal.MongoConnection connection, System.String databaseName, IMongoCommand command) [0x00000] in <filename unknown>:0 
  at MongoDB.Driver.MongoServerInstance.Ping (MongoDB.Driver.Internal.MongoConnection connection) [0x00000] in <filename unknown>:0 
  at MongoDB.Driver.MongoServerInstance.Connect () [0x00000] in <filename unknown>:0 
  at MongoDB.Driver.Internal.DirectMongoServerProxy.Connect (TimeSpan timeout, MongoDB.Driver.ReadPreference readPreference) [0x00000] in <filename unknown>:0 
  at Tacticsoft.Examples.SimpleTableViewController.FriendsHighscoreHndlr (IGraphResult FBresult) [0x00000] in <filename unknown>:0 
  at Facebook.Unity.AsyncRequestString+<Start>c__Iterator0.MoveNext () [0x00000] in <filename unknown>:0 
  at UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) [0x00000] in <filename unknown>:0 
Rethrow as MongoConnectionException: Unable to connect to server XXX.XXX.XX.XX:XXXX: Method not found: 'Default constructor not found...ctor() of MongoDB.Driver.CommandResultSerializer'..
  at MongoDB.Driver.Internal.DirectMongoServerProxy.Connect (TimeSpan timeout, MongoDB.Driver.ReadPreference readPreference) [0x00000] in <filename unknown>:0 
  at Tacticsoft.Examples.SimpleTableViewController.FriendsHighscoreHndlr (IGraphResult FBresult) [0x00000] in <filename unknown>:0 
  at Facebook.Unity.AsyncRequestString+<Start>c__Iterator0.MoveNext () [0x00000] in <filename unknown>:0 
  at UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) [0x00000] in <filename unknown>:0 

初始方法

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

返回查询结果

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

0 个答案:

没有答案