C# 中的 MongoDB 复合条件
使用 C# MongoDB 驱动程序时如何创建复合条件?
这有效:
mongoCollection = mdb.GetCollection("person");
BsonElement be1=new BsonElement("surname","Jones");
qryPattern = new QueryDocument(new BsonElement[] {be1});
foreach (MongoDB.Bson.BsonDocument doc in mongoCollection.FindAs<MongoDB.Bson.BsonDocument>(qryPattern))
{
rc.Append(doc.ToJson());
rc.Append("<br />");
}
但是我如何调整我的 BsonElement 以支持复合条件,例如
BsonElement be1=new BsonElement("surname","[Jones,Smith]");
或
BsonElement be1=new BsonElement("surname","Jones");
BsonElement be2=new BsonElement("surname","Smith");
qryPattern = new QueryDocument(new BsonElement[] {be1,be2});
非常感谢
How do I create compound condition when using the C# MongoDB driver?
This works:
mongoCollection = mdb.GetCollection("person");
BsonElement be1=new BsonElement("surname","Jones");
qryPattern = new QueryDocument(new BsonElement[] {be1});
foreach (MongoDB.Bson.BsonDocument doc in mongoCollection.FindAs<MongoDB.Bson.BsonDocument>(qryPattern))
{
rc.Append(doc.ToJson());
rc.Append("<br />");
}
But how do i adjust my BsonElement to support a compound condition, such as
BsonElement be1=new BsonElement("surname","[Jones,Smith]");
or even
BsonElement be1=new BsonElement("surname","Jones");
BsonElement be2=new BsonElement("surname","Smith");
qryPattern = new QueryDocument(new BsonElement[] {be1,be2});
Thanks very much
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这很简单,您应该使用
Query.In
:It's easy, you should use
Query.In
: