本文整理汇总了C#中MongoDB.Driver.QueryDocument.Add方法的典型用法代码示例。如果您正苦于以下问题:C# QueryDocument.Add方法的具体用法?C# QueryDocument.Add怎么用?C# QueryDocument.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDB.Driver.QueryDocument
的用法示例。
在下文中一共展示了QueryDocument.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: NumberCharactersOnServer
public int NumberCharactersOnServer(string region, string server)
{
QueryDocument query = new QueryDocument();
query.Add("Server", server);
query.Add("Region", region);
return (int)Collection.Find(query).Count();
}
示例3: 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;
}
示例4: 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);
}
}
示例5: GetCharactersInGuild
public IList<Character> GetCharactersInGuild(string region, string server, string guild)
{
QueryDocument query = new QueryDocument();
query.Add("Server", server);
query.Add("Region", region);
query.Add("Guild", guild);
return Collection.Find(query).OrderBy(c => c.CurrentPoints).ToList();
}
示例6: ListCharactersOnServerByPoints
public IList<Character> ListCharactersOnServerByPoints(string region, string server, int start, int limit)
{
QueryDocument query = new QueryDocument();
query.Add("Server", server);
query.Add("Region", region);
SortByBuilder sortBy = new SortByBuilder();
sortBy.Descending("CurrentPoints");
return Collection.Find(query).SetSortOrder(sortBy).SetSkip(start).SetLimit(limit).OrderByDescending(c => c.CurrentPoints).ToList();
}
示例7: GetChatMessage
public Message[] GetChatMessage(string user, bool delete)
{
if (string.IsNullOrEmpty(user))
return null;
user = user.ToLower();
var db = GetDatabase();
var collection = db.GetCollection("offline_msg");
var query = from x in collection.AsQueryable<OfflineMessageItem>() where x.To == user select x;
List<Message> msgs = new List<Message>();
foreach (var item in query)
{
msgs.Add(new Matrix.Xmpp.Client.Message()
{
From = item.From + "@gjtalk.com",
To = item.To + "@gjtalk.com",
Body = item.Body,
Delay = new Matrix.Xmpp.Delay.Delay(item.Time, item.From + "@gjtalkc.com"),
Type = (Matrix.Xmpp.MessageType)Enum.Parse(
typeof(Matrix.Xmpp.MessageType), item.MessageType)
});
}
if (delete)
{
QueryDocument doc = new QueryDocument();
doc.Add("To", user);
collection.Remove(doc);
}
return msgs.ToArray();
}
示例8: 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();
}
示例9: GetReport
public CarFacts GetReport(string Vin)
{
string DbName = "CarFactsDB";
ConnectedRepository fctx = new ConnectedRepository(DbName);
QueryDocument FaxQuery = new QueryDocument();
FaxQuery.Add("_id", Vin);
CarFacts carFaxReport = fctx.CarFacts.FindOne(FaxQuery);
return carFaxReport;
}
示例10: Forms
public ActionResult Forms(string id, string Project)
{
//var CVCollection = MongoDBHelper.GetCollection("ClinicalViewDocuments");
var query = new QueryDocument("project", Project.ToString());
query.Add("DatabaseGuid", id);
var ClinicalViews = CVCollection.Find(query);
var forms = CVCollection.Distinct("FormOid", query).OrderBy(x => x);
ViewBag.forms = forms;
return View();
}
示例11: GetByUser
public static IEnumerable<Report> GetByUser(IApiUserSource api, User user)
{
using (MongoConnection db = FooRuntime.GetDatabase())
{
QueryDocument query = new QueryDocument();
query.AddApiConstraint(api);
query.Add("ownerUserId", user._id);
return db.GetCollection<Report>().Find(query);
}
}
示例12: GetByToken
public static Token GetByToken(IApiUserSource api, Guid token)
{
using (MongoConnection db = FooRuntime.GetDatabase())
{
QueryDocument query = new QueryDocument();
query.AddApiConstraint(api);
query.Add(TheTokenKey, token);
return db.GetCollection<Token>().FindOne(query);
}
}
示例13: GetFeature
public Features GetFeature(string carName)
{
string DbName = "CarFeaturesDB";
ConnectedRepository fctx = new ConnectedRepository(DbName);
QueryDocument FeatureQuery = new QueryDocument();
FeatureQuery.Add("CarName", carName);
Features featuresOfCar = fctx.Features.FindOne(FeatureQuery);
if (featuresOfCar != null)
return featuresOfCar;
else
return null;
}
示例14: Forms
public ActionResult Forms(string id,string Project)
{
if (id == null || id == "")
return new RedirectResult("./Databases");
if (Project == null || Project == "")
return new RedirectResult("./Project/?id="+id);
var query = new QueryDocument("DatabaseGuid", id);
query.Add("project", Project);
var Forms = CVCollection.Distinct("FormOid", query).OrderBy(x => x);
ViewBag.Forms = Forms;
ViewBag.dbId = id;
ViewBag.Project = Project;
return View();
}
示例15: GetById
public static User GetById(IApiUserSource api, ObjectId userId, bool throwIfNotFound)
{
using (MongoConnection db = FooRuntime.GetDatabase())
{
QueryDocument query = new QueryDocument();
query.AddApiConstraint(api);
query.Add(IdKey, userId);
User user = db.GetCollection<User>().FindOne(query);
if (user != null)
return user;
else
{
if (throwIfNotFound)
throw new InvalidOperationException(string.Format("A user with ID '{0}' was not found.", userId));
else
return null;
}
}
}