• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Driver.QueryDocument类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中MongoDB.Driver.QueryDocument的典型用法代码示例。如果您正苦于以下问题:C# QueryDocument类的具体用法?C# QueryDocument怎么用?C# QueryDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



QueryDocument类属于MongoDB.Driver命名空间,在下文中一共展示了QueryDocument类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
        }
开发者ID:bobwohler,项目名称:MongoDBRnD,代码行数:26,代码来源:MongoDBTests.cs


示例2: ParseQuery

        public static IMongoQuery ParseQuery(string query)
        {
            var parsedQuery     = BsonDocument.Parse(query);
            var queryDocument   = new QueryDocument(parsedQuery);

            return queryDocument;
        }
开发者ID:BernhardGlueck,项目名称:Phare,代码行数:7,代码来源:MongoDbUtilities.cs


示例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);
            }
        }
开发者ID:benlowry,项目名称:mono-service-wrapper,代码行数:25,代码来源:DataStore.cs


示例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;
        }
开发者ID:Naresh-Nelavalli,项目名称:TraumenAuto,代码行数:36,代码来源:MongoCarData.cs


示例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();
        }
开发者ID:yuechuanbingzhi163,项目名称:GJTalk,代码行数:28,代码来源:OfflineMessageManager.cs


示例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);
            }
        }
开发者ID:brosen,项目名称:CVServicePoc,代码行数:36,代码来源:ReportingRecordController.cs


示例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;
        }
开发者ID:azanium,项目名称:PopBloop-Unity,代码行数:31,代码来源:DbManager.cs


示例8: Remove

        public bool Remove(Entity entity)
        {
            var queryDoc = new QueryDocument {{EntityIdName, entity.Id}};

            var result = Collection.Remove(queryDoc);
            return result.Ok;
        }
开发者ID:ktj007,项目名称:mmo,代码行数:7,代码来源:MongoBind.cs


示例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);
        }
开发者ID:KlaudWerk,项目名称:WSHumanTask,代码行数:30,代码来源:TestMongoPersistence.cs


示例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();
     }
 }
开发者ID:jefth,项目名称:EasyMongo,代码行数:26,代码来源:BinaryPredicate.cs


示例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;
        }
开发者ID:azanium,项目名称:PopBloop-Unity,代码行数:31,代码来源:Program.cs


示例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();
 }
开发者ID:brosen,项目名称:CVServicePoc,代码行数:10,代码来源:ClinicalViewController.cs


示例13: TestAndWithAll

 public void TestAndWithAll()
 {
     var all = new QueryDocument();
     var query = Query.And(all);
     var expected = "{ }";
     Assert.AreEqual(expected, query.ToJson());
 }
开发者ID:narutoswj,项目名称:mongo-csharp-driver,代码行数:7,代码来源:CSharp653Tests.cs


示例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();
        }
开发者ID:softiger,项目名称:MongoDBSample,代码行数:34,代码来源:Program.cs


示例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;
             }
        }
    }
开发者ID:ceie246,项目名称:MIPS246_Software,代码行数:25,代码来源:MIPS246UserManager.cs


示例16: find

        public dynamic find(MongoCollection collection,object[] args)
        {
            Type type = args[0].GetType();

            if(type.Name.Contains("<>__AnonType")){

                PropertyInfo[] properties = type.GetProperties();
                Dictionary<string,object> dictionary = new Dictionary<string, object>();
                foreach(var property in properties)
                    dictionary[property.Name] = property.GetValue(args[0],null);

                var query = new QueryDocument(dictionary);
                var result = collection.FindAs<BsonDocument>(query);
                List<Entity> documents = new List<Entity>();

                if(result.Size() > 0)
                {
                    foreach(var entity in result)
                        documents.Add(new Entity(entity));
                }

                return documents;
            }
            throw new NotImplementedException("Only annonymous types are accepted for Queries.");
        }
开发者ID:blackorzar,项目名称:DMongo,代码行数:25,代码来源:DBExpando.cs


示例17: 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();
        }
开发者ID:yuechuanbingzhi163,项目名称:GJTalk,代码行数:31,代码来源:OfflineMessageManager.cs


示例18: Index

 public ActionResult Index()
 {
     Resume re = new Resume();
     QueryDocument query = new QueryDocument("resumeCode", "darylchymko1");
     re = _collection.FindOne(query);
     return View("Resume", re);
 }
开发者ID:dchymko,项目名称:MongoResume,代码行数:7,代码来源:ResumeController.cs


示例19: 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();
 }
开发者ID:blat001,项目名称:Achievement-Sherpa,代码行数:7,代码来源:MongoWorldRepository.cs


示例20: Main

    static void Main()
    {

      // Create seed data

      BsonDocument[] seedData = CreateSeedData();

      // Standard URI format: mongodb://[dbuser:[email protected]]host:port/dbname

      String uri = "mongodb://user:[email protected]:port/db";
      
      MongoUrl url = new MongoUrl(uri);
      MongoClient client = new MongoClient(url);
      MongoServer server = client.GetServer();
      MongoDatabase db = server.GetDatabase(url.DatabaseName);
      
      /*
       * First we'll add a few songs. Nothing is required to create the
       * songs collection; it is created automatically when we insert.
       */
      
      var songs = db.GetCollection<BsonDocument>("songs");

       // Use Insert for single BsonDocument insertion.

      songs.InsertBatch(seedData);

      /*
       * Then we need to give Boyz II Men credit for their contribution to
       * the hit "One Sweet Day".
       */
    
      QueryDocument updateQuery = new QueryDocument{ { "Title", "One Sweet Day" } };

      songs.Update(updateQuery, new UpdateDocument{ { "$set", new BsonDocument( "Artist", "Mariah Carey ft. Boyz II Men") } });

      /*
       * Finally we run a query which returns all the hits that spent 10 
       * or more weeks at number 1.
       */

      QueryDocument findQuery = new QueryDocument{ { "WeeksAtOne", new BsonDocument{ { "$gte", 10 } } } };
      var cursor = songs.Find(findQuery).SetSortOrder(SortBy.Ascending("Decade"));
      
      foreach (var song in cursor) 
      {
        var test = song["Decade"];
        Console.WriteLine("In the {0}, {1} by {2} topped the charts for {3} straight weeks",
          song["Decade"], song["Title"], song["Artist"], song["WeeksAtOne"]);
      }

      // Since this is an example, we'll clean up after ourselves.

      songs.Drop();

      // Only disconnect when your app is terminating.

      server.Disconnect();
    }
开发者ID:ZackCaoEsna,项目名称:mongodb-driver-examples,代码行数:59,代码来源:CSharpSimpleExample.cs



注:本文中的MongoDB.Driver.QueryDocument类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Driver.SafeMode类代码示例发布时间:2022-05-26
下一篇:
C# Driver.MongoUrlBuilder类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap