2016-03-31 10 views
0

mongodbデータベースを照会して、c#を使用して2つの日付間の特定のフィールドのすべての値を検索したい。 コレクション内の特定のフィールドを照会する方法を教えてください。私が想定し特定のフィールドのすべての値を検索するためにmongodbデータベースを照会する#


これは私のコレクション "工夫" であると私は "ハイ" のすべての値を照会しようと

public class Devise 
{ 
    public string parité { get; set; } 
    public float low { get; set; } 
    public float high { get; set; } 
    public DateTime date_observation { get; set; } 

} 

これは私のクエリ・コード

public class Devisedata 
{ 
    private IMongoDatabase _database; 

    public async System.Threading.Tasks.Task<List<Devise>> GetDataDevise(DateTime inputDate1, DateTime inputDate2) 
    { 

     var collection = _database.GetCollection<Devise>("datafinance"); 
     var builder = Builders<Devise>.Filter; 
     var filter = builder.Gte("date_observation", inputDate1) & 
        builder.Lt("date_observation", inputDate2.AddDays(1)); 


     var list = await collection.Find(filter).ToListAsync(); 
     return list; 
    } 
} 

答えて

0

です「すべての値を見つける」とは、すべての値がhighの値であることを意味します。 その場合は、以下の例のようにこれを行うことができます:

var builder = Builders<Devise>.Filter; 
var filter = builder.Gte("date_observation", inputDate1) & 
       builder.Lt("date_observation", inputDate2.AddDays(1)); 

var cursor = await collection.DistinctAsync<double>("high", match); 
await cursor.ForEachAsync(doc => Console.WriteLine(doc)); 

詳細についてはMongoCollection.Distinctdb.collection.distinct()を参照してください。

上記のスニペットは、C# Driver v2.2.3でテストされ、MongoDB v3.2

関連する問題