gpt4 book ai didi

c# - MongoDB 不查询

转载 作者:可可西里 更新时间:2023-11-01 09:12:55 25 4
gpt4 key购买 nike

您好,我正在尝试通过使用 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 "";
}
}

返回查询结果

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

最佳答案

您是否尝试过使用来自 Mongo 的 .NET 驱动程序的过滤器?

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

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

关于c# - MongoDB 不查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44191581/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com