本文整理汇总了C#中MongoDB.Driver.QueryDocument类的典型用法代码示例。如果您正苦于以下问题:C# QueryDocument类的具体用法?C# QueryDocument怎么用?C# QueryDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
QueryDocument类属于MongoDB.Driver命名空间,在下文中一共展示了QueryDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Get_Foo_ByID
public void Get_Foo_ByID()
{
#region Test setup
MongoCollection<Foo> fooCollection = _database.GetCollection<Foo>(_collectionName);
fooCollection.RemoveAll();
BsonDocument fooDocEthan = new BsonDocument {
{ "_id", _bobFooId },
{ "name", "Bob"}
};
BsonDocument fooDocAbby = new BsonDocument {
{ "_id", _hollyFooId },
{ "name", "Holly" }
};
fooCollection.Insert(fooDocEthan);
fooCollection.Insert(fooDocAbby);
#endregion
QueryDocument query = new QueryDocument("_id", _bobFooId);
Foo foo = fooCollection.FindOne(query);
Assert.AreEqual(foo.Name, "Bob");
#region Test cleanup
fooCollection.RemoveAll();
#endregion
}
示例2: ParseQuery
public static IMongoQuery ParseQuery(string query)
{
var parsedQuery = BsonDocument.Parse(query);
var queryDocument = new QueryDocument(parsedQuery);
return queryDocument;
}
示例3: SetStatus
public static void SetStatus(BsonDocument service, bool restart)
{
try
{
var server = MongoServer.Create(ConfigurationManager.ConnectionStrings["mongodb"].ConnectionString);
server.Connect();
var database = server.GetDatabase("config");
var collection = database.GetCollection("services");
var filter = new QueryDocument { { "_id", service["_id"].AsObjectId } };
var update = new UpdateDocument();
foreach (var key in service)
update[key.Name] = key.Value;
update["restart"] = restart;
collection.Update(filter, update);
server.Disconnect();
}
catch (Exception err)
{
Console.WriteLine("** error updating restart status: " + err.Message);
}
}
示例4: GetCars
//# Function to list of cars that are eligible for users request
public List<Car> GetCars(InputRequestAttributes RequestQuery)
{
//# Get the list of zipcodes that are located in specified distance from user requested zipcode
ConnectedRepository ctx = new ConnectedRepository(DbName);
LocationDataLayer lctx = new LocationDataLayer();
List<string> NearByZipCodes = new List<string>();
if (!string.IsNullOrEmpty(RequestQuery.Zipcode))
{
List<Location> locationsAround = lctx.GetNearZipcodes(RequestQuery.Zipcode,RequestQuery.distance);
if (locationsAround.Count != 0)
{
foreach (Location location in locationsAround)
{
NearByZipCodes.Add(location.zip);
}
NearByZipCodes.Add(RequestQuery.Zipcode);
}
}
//# Build a DB query based on user constraint. Check request if it has value and add it to query.
QueryDocument CarQuery = new QueryDocument();
if (RequestQuery.Year > 2000)
CarQuery.Add("Year", RequestQuery.Year);
if (RequestQuery.Name != null)
CarQuery.Add("Name", RequestQuery.Name);
if (RequestQuery.Maker != null)
CarQuery.Add("Maker", RequestQuery.Maker);
if (RequestQuery.MaxPrice >= 1000)
CarQuery.Add("Price", new BsonDocument("$lt", RequestQuery.MaxPrice));
if (NearByZipCodes.Count() != 0)
CarQuery.Add("Zipcode", new BsonDocument("$in", new BsonArray(NearByZipCodes)));
MongoCursor<Car> Cars = ctx.Cars.Find(CarQuery);
List<Car> carsList = Cars.ToList();
return carsList;
}
示例5: GetPresence
public Presence[] GetPresence(string from, string to, Matrix.Xmpp.PresenceType? type, bool remove)
{
List<Presence> presences = new List<Presence>();
var db = GetDatabase();
var collection = db.GetCollection("offline_presence");
var query = new QueryDocument();
if (from != null)
query.Add("from", from);
if (to != null)
query.Add("to", to);
if (type != null)
query.Add("type", type.ToString());
MongoCursor<BsonDocument> cursor;
if (from == null && to == null)
cursor = collection.FindAll();
else
cursor = collection.Find(query);
foreach (var item in cursor)
{
Presence presence = (Presence)Presence.LoadXml(item.GetValue("value").AsString);
presences.Add(presence);
}
if (remove)
collection.Remove(query);
return presences.ToArray();
}
示例6: Get
// GET api/reportingrecord/5
public HttpResponseMessage Get(string id, [FromBody]JObject JsonObject)
{
//Setup variables From Body
JToken Project;
JToken Oid;
JToken Format;
JToken userRole;
JsonObject.TryGetValue("Project", out Project);
JsonObject.TryGetValue("FormOid", out Oid);
JsonObject.TryGetValue("Format", out Format);
//just for POC, needs to be derived
JsonObject.TryGetValue("Role", out userRole);
if(Project==null ||Oid==null|| Format==null)
return Request.CreateResponse(HttpStatusCode.BadRequest);
userRole = userRole ?? 0;
//Run Query against database and pull back records
var query = new QueryDocument("project", Project.ToString());
query.Add("FormOid", Oid.ToString());
query.Add("DatabaseGuid", id);
var ClinicalViews = CVCollection.Find(query);
//Build Matrix from records and Create output
switch(Format.ToString().ToLower())
{
case "csv":
return GetCsvOutput(ClinicalViews, int.Parse(userRole.ToString()));
case "json":
return GetjsonOutput(ClinicalViews, int.Parse(userRole.ToString()));
default:
return Request.CreateResponse(HttpStatusCode.NotImplemented);
}
}
示例7: FetchEquipments
public Equipments FetchEquipments(string userid)
{
Equipments equipments = new Equipments();
try
{
MongoServer server = MongoServer.Create(DbSettings.ConnectionString);
MongoDatabase db = server.GetDatabase(DbConstants.DbNameGame, Credentials, new SafeMode(true));
MongoCollection<BsonDocument> coll = db.GetCollection(DbConstants.CollectionNameEquipments);
QueryDocument query = new QueryDocument("userid", userid);
var cursor = coll.Find(query);
foreach (BsonDocument item in cursor)
{
string code = item["code"].AsString;
int count = item["count"].IsString ? Int32.Parse(item["count"].AsString) : item["count"].AsInt32;
equipments.Items.Add(code, count);
}
server.Disconnect();
}
catch (Exception ex)
{
log.Error("FetchEquipments: " + ex.ToString());
}
return equipments;
}
示例8: Remove
public bool Remove(Entity entity)
{
var queryDoc = new QueryDocument {{EntityIdName, entity.Id}};
var result = Collection.Remove(queryDoc);
return result.Ok;
}
示例9: TestMongoInteraction
public void TestMongoInteraction()
{
MongoServer server = MongoServer.Create();
if (server.DatabaseExists(PropSetCollectionsDb))
server.DropDatabase(PropSetCollectionsDb);
MongoDatabase testDb = server.GetDatabase(PropSetCollectionsDb);
if (testDb.CollectionExists("ut_collection"))
testDb.DropCollection("ut_collection");
MongoCollection<MongoPropertyElement> collection =
testDb.GetCollection<MongoPropertyElement>("ut_collection");
collection.EnsureIndex(IndexKeys.Ascending("Name"),IndexOptions.SetUnique(true));
MongoPropertyElement el = new MongoPropertyElement("one");
collection.Insert(el,SafeMode.True);
collection.Insert(new MongoPropertyElement("two"),SafeMode.True);
try
{
collection.Insert(new MongoPropertyElement("one"), SafeMode.True);
Assert.Fail("Duplicate key insert");
}
catch(MongoSafeModeException ex)
{
}
Assert.AreEqual(2, collection.Count());
QueryDocument query=new QueryDocument("Name","one");
MongoPropertyElement ee = collection.FindOne(query);
Assert.IsNotNull(ee);
}
示例10: Fill
public void Fill(IPropertyPredicateOperator optr, QueryDocument doc)
{
switch (this.OpType)
{
case ExpressionType.Equal:
optr.PutEqualPredicate(doc, this.Constant);
break;
case ExpressionType.NotEqual:
optr.PutNotEqualPredicate(doc, this.Constant);
break;
case ExpressionType.GreaterThan:
optr.PutGreaterThanPredicate(doc, this.Constant);
break;
case ExpressionType.GreaterThanOrEqual:
optr.PutGreaterThanOrEqualPredicate(doc, this.Constant);
break;
case ExpressionType.LessThan:
optr.PutLessThanPredicate(doc, this.Constant);
break;
case ExpressionType.LessThanOrEqual:
optr.PutLessThanOrEqualPredicate(doc, this.Constant);
break;
default:
throw new NotSupportedException();
}
}
示例11: FetchEquipments
public static Equipments FetchEquipments(string userid)
{
Equipments equipments = new Equipments();
try
{
MongoServer server = MongoServer.Create("mongodb://127.0.0.1:27017");
MongoDatabase db = server.GetDatabase("Game", Credentials, new SafeMode(true));
MongoCollection<BsonDocument> coll = db.GetCollection("Equipments");
QueryDocument query = new QueryDocument("userid", userid);
var cursor = coll.Find(query);
foreach (BsonDocument item in cursor)
{
string code = item["code"].AsString;
int count = item["count"].AsInt32;
equipments.Items.Add(code, count);
}
server.Disconnect();
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
}
return equipments;
}
示例12: Details
//
// GET: /ClinicalView/Details/5
// Sample: http://localhost:64628/ClinicalView/details/6ea9c26ac9ea41ab9cb7483a00c8afcb9797528
public ActionResult Details(string id)
{
var query = new QueryDocument("_id", id);
var doc = CVCollection.FindOne(query);
ViewBag.doc = doc.ToString();
return View();
}
示例13: TestAndWithAll
public void TestAndWithAll()
{
var all = new QueryDocument();
var query = Query.And(all);
var expected = "{ }";
Assert.AreEqual(expected, query.ToJson());
}
示例14: Main
static void Main(string[] args)
{
//连接信息
string conn = "mongodb://localhost";
string database = "demoBase";
string collection = "demoCollection";
MongoServer mongodb = MongoServer.Create(conn);
//连接数据库
MongoDatabase mongoDataBase = mongodb.GetDatabase(database);
//选择数据库名
MongoCollection mongoCollection = mongoDataBase.GetCollection(collection);
//选择集合,相当于表
mongodb.Connect();
//普通插入
var o = new { Uid = 123, Name = "xixiNormal", PassWord = "111111" };
mongoCollection.Insert(o);
//对象插入
Person p = new Person { Uid = 124, Name = "xixiObject", PassWord = "222222" };
mongoCollection.Insert(p);
//BsonDocument 插入
BsonDocument b = new BsonDocument();
b.Add("Uid", 125);
b.Add("Name", "xixiBson");
b.Add("PassWord", "333333");
mongoCollection.Insert(b);
Console.WriteLine(mongoCollection.FullName);
QueryDocument query = new QueryDocument();
query.Add("Uid", 125);
MongoCursor<Person> pers = mongoCollection.FindAs<Person>(query);
//Console.WriteLine(pe.Name);
Console.ReadLine();
}
示例15: CheckUser
public static User CheckUser(string id, string password)
{
MongoServer server = MongoServer.Create(connectionString);
MongoDatabase db = server.GetDatabase(dbString);
MongoCollection collection = db.GetCollection(collectionString);
var query = new QueryDocument("StudentID", id);
if(collection.Count(query)==0)
{
return null;
}
else
{
User result = collection.FindOneAs<User>(query);
if(result.Password==HashMD5(password))
{
return result;
}
else
{
return null;
}
}
}