-1
私のC#コンソールアプリケーションプロジェクトで、MongoDB.Driver.2.4.3をMongoDB 3.2.10に接続して使用しています。c#mongodbコレクション数とasqueryableからのドキュメント結果を確認
フィルタリングされたクエリの最初と最後のドキュメントを検索するにはどうすればよいですか?
static void Main(string[] args)
{
DateTime myTimeConvert = DateTime.Now;
var client = new MongoClient("mongodb://localhost:27017");
var DB = client.GetDatabase("football");
var players = DB.GetCollection<Player>("players");
var playersInBrazil = players.AsQueryable()
.Where(p => p.country == "Brazil");
//count the number of documents and find the first and the last document from the filtered query
}
internal class Player
{
public ObjectId Id { get; set; }
public string firstname { get; set; }
public BsonDateTime birthdate { get; set; }
public string country { get; set; }
public double goals { get; set; }
}
}
感謝 - countPlayersInBrazilとfirstPlayersInBrazil変数は動作しますが、lastPlayersInBrazilのために、私はエラーを取得:未処理の例外:System.NotSupportedException:集計([]):メソッド最後は、式ツリーではサポートされていません。最後(p =>(p.country == "ブラジル"))。 – ikask
私はこれらを実行してvariables.Console.WriteLine(countPlayersInBrazil)をテストしました。 Console.WriteLine(firstPlayersInBrazil.firstname); Console.WriteLine(lastPlayersInBrazil.firstname); – ikask
私はFirstがサポートされているが、Lastはサポートされていないとは思う。私はあなたがこの働くSPを次のようにしたいと思う。 players.AsQueryable()。Where(p => p.country == "Brazil")。ToList()。その後、カウントを行います。それからあなたはモンゴの世界を去った。最も効果的ではありませんが、ブラジルには多くの選手がいないはずです:) – SJFJ