2016-09-19 3 views
0

MongoDB C#で次のクエリを実行中に問題が発生しました。 mongoクライアントのコードはMongoDB C#Driverの "Or"ステートメントの使い方は?

db.collection.find({ $or: [ { quantity: { $lt: 20 } }, { price: 10 } ,{price:100},{name:"x"}] }) 

ですが、どのようにC#で同じ質問をするのですか? 私はモンゴCシャープドライバ1.9.2を使用しています

var match = new BsonDocument() { { "$match", new BsonDocument { {"type":"food" } } } }; 
var project = new BsonDocument(){ { "$project", new BsonDocument{ { "name", 1 } { "quantity", 1 } } } }; 
AggregateArgs AggregationPipeline = new AggregateArgs() { Pipeline = new[] { match, project } }; 
var aggregate = Collection.Aggregate(AggregationPipeline); 

として次のmongoクライアントコード声明

db.collection.find({type:"food"},{name:1,quantity:1}) 

を照会することができました。おかげさまで

答えて

1

まず、ビルダーを追加します。

var builder = Builders<BsonDocument>.Filter; 

次に、このようなフィルタ:

var filter = builder.Lt("quantity", 20) | builder.Eq("price", 10) | other stuff) 

そして最後のようなもの:

db.collection.Find(filter).ToList(); 
+0

こんにちは@Mahdiを、私はMongoCSharpDriverを使用しています。 1.9.2。ビルダーのコンテキストはこのバージョンには存在しません。ありがとう – coder

関連する問題