当前位置: 首页>>代码示例>>C#>>正文


C# Driver.Document类代码示例

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


Document类属于MongoDB.Driver命名空间,在下文中一共展示了Document类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ShouldReturnAllDataFromCollection

        public void ShouldReturnAllDataFromCollection()
        {
            //Given
            Mongo db = new Mongo(string.Format("Server={0}:{1}", "localhost", "27017"));
            db.Connect();
            IMongoCollection collection = db["test"]["folks"];
            Document doc1 = new Document() { { "first_name", "Bill" }, { "middle_initial", "Q" }, { "last_name", "Jackson" }, { "address", "744 Nottingham St." } };
            Document doc2 = new Document() { { "first_name", "Ralph" }, { "middle_initial", "M" }, { "last_name", "Buckingham" }, { "state", "CA" } };
            Document doc3 = new Document() { { "first_name", "Ronald" }, { "middle_initial", "Q" }, { "last_name", "Weasly" }, { "city", "Santa Rosa" } };
            collection.Insert(doc1);
            collection.Insert(doc2);
            collection.Insert(doc3);
            var queryProvider = new MongoDbCSharpQuery();

            try
            {
                //When
                IEnumerable data = queryProvider.RunQuery("localhost", "test", "27017", "folks");

                int numberOfRows = 0;
                foreach (var row in data) numberOfRows++;

                //Then
                Assert.AreEqual(3, numberOfRows);
            }
            finally
            {
                //Clean Up
                collection.Delete(doc1);
                collection.Delete(doc2);
                collection.Delete(doc3);
                queryProvider.Dispose();
            }
        }
开发者ID:nicklv,项目名称:MongoDB-Management-Studio,代码行数:34,代码来源:MongoDbCSharpTest.cs

示例2: GridChunk

 public GridChunk(Document doc)
 {
     this.id = (Oid)doc["_id"];
     this.filesId = (Object)doc["files_id"];
     this.n = Convert.ToInt32(doc["n"]);
     this.data = (Binary)doc["data"];
 }
开发者ID:deadtrickster,项目名称:mongodb-csharp,代码行数:7,代码来源:GridChunk.cs

示例3: ShouldCopyDataToClipboard

        public void ShouldCopyDataToClipboard()
        {
            //Given
            DictionaryBase doc1 = new Document() { { "first_name", "Bill" }, { "middle_initial", "Q" }, { "last_name", "Jackson" }, { "address", "744 Nottingham St." } };
            DictionaryBase doc3 = new Document() { { "first_name", "Ronald" }, { "middle_initial", "Q" }, { "last_name", "Weasly" }, { "city", "Santa Rosa" } };
            IList<DictionaryBase> documents = new List<DictionaryBase>() { doc1, doc3 };
            IMongoQuery query = MockRepository.GenerateStub<IMongoQuery>();
            query.Stub(q => q.RunQuery("localhost", "test", "27017", "folks:this.middle_initial == 'Q'")).Return(documents);
            IMongoQueryFactory queryFactory = MockRepository.GenerateStub<IMongoQueryFactory>();
            queryFactory.Stub(factory => factory.BuildQuery()).Return(query);
            IClipboardService clipboardService = MockRepository.GenerateMock<IClipboardService>();
            IUserMessageService messageService = MockRepository.GenerateMock<IUserMessageService>();

            MainViewModel viewModel = new MainViewModel(queryFactory)
                                          {
                                              Server = "localhost",
                                              Database = "test",
                                              Port = "27017",
                                              Query = "folks:this.middle_initial == 'Q'",
                                              ClipboardService = clipboardService,
                                              UserMessageService = messageService
                                          };

            //When
            viewModel.RunQueryCommand.Execute(null);
            viewModel.CopyToClipboardCommand.Execute(null);

            //Then
            clipboardService.AssertWasCalled(clipboard => clipboard.SetText(
                                                              "last_name\tfirst_name\tmiddle_initial\taddress\tcity\t\r\nJackson\tBill\tQ\t744 Nottingham St.\t\t\r\nWeasly\tRonald\tQ\t\tSanta Rosa\t\r\n"));
            messageService.AssertWasCalled(service => service.ShowMessage("Results copied to clipboard"));
        }
开发者ID:PatrickGannon,项目名称:MongoDB-Management-Studio,代码行数:32,代码来源:MainViewModelTest.cs

示例4: CreateNut

        /// <summary>
        /// Create a Nut for a specific application account and in a specific configuration container.
        /// </summary>
        /// <param name="account">The application account we are creating the nut for.</param>
        /// <param name="container">The container we are inserting the nut into (e.g. connectionstrings, endpoints, appconfig, etc).</param>
        /// <param name="nut">Busta nut.</param>
        /// <returns>True if the nut was added and false if it already exists, and therefore was not added/updated.</returns>
        public static bool CreateNut(string account, string container, Nut nut)
        {
            bool nutAdded = false;

            Mongo mongo = new Mongo();
            mongo.Connect();

            var db = mongo.GetDatabase(WellKnownDb.AppConfiguration);

            var collection = db.GetCollection(container);

            var doc = new Document();

            doc["account"] = account;
            doc["name"] = nut.Key;
            doc["value"] = nut.Value;

            if (nut.Properties != null)
            {
                foreach (var k in nut.Properties.Keys)
                {
                    doc.Add(k, nut.Properties[k]);
                }
            }

            if (collection.FindOne(doc) == null)
            {
                collection.Insert(doc);
                nutAdded = true;
            }

            return nutAdded;
        }
开发者ID:zachbonham,项目名称:squirrel,代码行数:40,代码来源:SquirrelBusinessLogic.cs

示例5: Post

        public async Task<Document> Post(Document document)
        {
            document.Key = ObjectId.GenerateNewId().ToString();
            await _documents.InsertOneAsync(document);

            return document;
        }
开发者ID:jdhuntington,项目名称:mongo-test,代码行数:7,代码来源:DocumentsController.cs

示例6: DBRef

 public DBRef(Document doc)
 {
     if(IsDocumentDBRef(doc) == false) throw new ArgumentException("Document is not a valid DBRef");
     collectionName = (String)doc[DBRef.RefName];
     id = doc[DBRef.IdName];
     this.doc = doc;
 }
开发者ID:rodolfograve,项目名称:mongodb-csharp,代码行数:7,代码来源:DBRef.cs

示例7: Copy

        /// <summary>
        /// Copies one file to another.  The destination file must not exist or an IOException will be thrown.
        /// </summary>
        /// <exception cref="FileNotFoundException">Source file not found.</exception>
        /// <exception cref="IOException">Destination file already exists.</exception>
        /// <exception cref="MongoCommandException">A database error occurred executing the copy function.</exception>
        public void Copy(String src, String dest)
        {
            if(Exists(src) == false) throw new FileNotFoundException("Not found in the database.", src);
            if(Exists(dest) == true) throw new IOException("Destination file already exists.");

            Document scope = new Document().Append("bucket", this.name).Append("srcfile", src).Append("destfile",dest);
            String func ="function(){\n" +
                            //"   print(\"copying \" + srcfile);\n" +
                            "   var files = db[bucket + \".files\"];\n" +
                            "   var chunks = db[bucket + \".chunks\"];\n" +
                            "   var srcdoc = files.findOne({filename:srcfile});\n" +
                            //"   return srcdoc; \n" +
                            "   if(srcdoc != undefined){\n" +
                            "       var srcid = srcdoc._id;\n" +
                            "       var newid = ObjectId();\n" +
                            "       srcdoc._id = newid\n" +
                            "       srcdoc.filename = destfile;\n" +
                            "       files.insert(srcdoc);\n" +
                            "       chunks.find({files_id:srcid}).forEach(function(chunk){\n" +
                            //"           print(\"copying chunk...\");\n" +
                            "           chunk._id = ObjectId();\n" +
                            "           chunk.files_id = newid;\n" +
                            "           chunks.insert(chunk);\n" +
                            "       });\n" +
                            "       return true;\n" +
                            "   }\n" +
                            "   return false;\n" +
                            "}";
            Document result = db.Eval(func,scope);
        }
开发者ID:kvnsmth,项目名称:mongodb-csharp,代码行数:36,代码来源:GridFile.cs

示例8: TestRemove

 public void TestRemove()
 {
     Document d = new Document();
     d["one"] = 1;
     d.Remove("one");
     Assert.IsFalse(d.Contains("one"));
 }
开发者ID:jesseemerick,项目名称:mongodb-csharp,代码行数:7,代码来源:TestDocument.cs

示例9: ShouldPullInDataFromQueryProvider

        public void ShouldPullInDataFromQueryProvider()
        {
            //Given
            DictionaryBase doc1 = new Document() { { "first_name", "Bill" }, { "middle_initial", "Q" }, { "last_name", "Jackson" }, { "address", "744 Nottingham St." } };
            DictionaryBase doc3 = new Document() { { "first_name", "Ronald" }, { "middle_initial", "Q" }, { "last_name", "Weasly" }, { "city", "Santa Rosa" } };
            IList<DictionaryBase> documents = new List<DictionaryBase>() {doc1, doc3};
            IMongoQuery query = MockRepository.GenerateStub<IMongoQuery>();
            query.Stub(q => q.RunQuery("localhost", "test", "27017", "folks:this.middle_initial == 'Q'")).Return(documents);
            IMongoQueryFactory queryFactory = MockRepository.GenerateStub<IMongoQueryFactory>();
            queryFactory.Stub(factory => factory.BuildQuery()).Return(query);

            MainViewModel viewModel = new MainViewModel()
            {
                Server = "localhost", Database = "test", Port = "27017",
                Query = "folks:this.middle_initial == 'Q'",
                MongoQueryFactory = queryFactory
            };

            //When
            viewModel.RunQueryCommand.Execute(null);

            //Then
            Assert.AreEqual(2, viewModel.Items.Count);
            Assert.AreEqual(5, viewModel.Headers.Count);
        }
开发者ID:nicklv,项目名称:MongoDB-Management-Studio,代码行数:25,代码来源:MainViewModelTest.cs

示例10: TestEvalWithScope

 public void TestEvalWithScope()
 {
     int val = 3;
     Document scope = new Document().Append("x",val);
     Document result = db.Eval("function(){return x;}", scope);
     Assert.AreEqual(val, result["retval"]);
 }
开发者ID:karanbajaj,项目名称:mongodb-csharp,代码行数:7,代码来源:TestDatabase.cs

示例11: TestBuilderSetsAllProperties

        public void TestBuilderSetsAllProperties()
        {
            Document query = new Document().Append("x",1);
            Document scope = new Document().Append("y",2);
            Document sort = new Document().Append("z",3);
            MapReduceBuilder mrb = mrcol.MapReduceBuilder();
            mrb.Map(mapfunction)
                    .Reduce(reducefunction)
                    .KeepTemp(true)
                    .Limit(5)
                    .Out("outtest")
                    .Query(query)
                    .Scope(scope)
                    .Sort(sort)
                    .Verbose(false);

            MapReduce mr = mrb.MapReduce;
            Assert.AreEqual(query.ToString(), mr.Query.ToString());
            Assert.AreEqual(scope.ToString(), mr.Scope.ToString());
            Assert.AreEqual(sort.ToString(), mr.Sort.ToString());
            Assert.AreEqual(true, mr.KeepTemp);
            Assert.AreEqual(5, mr.Limit);
            Assert.AreEqual("outtest", mr.Out);
            Assert.AreEqual(false, mr.Verbose);
        }
开发者ID:kvnsmth,项目名称:mongodb-csharp,代码行数:25,代码来源:TestMapReduceBuilder.cs

示例12: SaveToDataStore

        public override void SaveToDataStore(BlogEngine.Core.DataStore.ExtensionType exType, string exId, object settings)
        {
            XmlSerializer xs = new XmlSerializer(settings.GetType());
            string objectXML = string.Empty;
            using (StringWriter sw = new StringWriter())
            {
                xs.Serialize(sw, settings);
                objectXML = sw.ToString();
            }

            using (var mongo = new MongoDbWr())
            {
                var coll = mongo.BlogDB.GetCollection("DataStoreSettings");

                Document spec = new Document();
                spec["ExtensionType"] = exType;
                spec["ExtensionId"] = exId;

                var res = new Document();
                res["Settings"] = objectXML;
                res["ExtensionType"] = exType;
                res["ExtensionId"] = exId;

                coll.Update(res, spec, UpdateFlags.Upsert);
            }
        }
开发者ID:tikalk,项目名称:fuse.dotnet.mongodb-blogengine,代码行数:26,代码来源:DataStore.cs

示例13: ShouldReturnCollectionsFromDatabase

        public void ShouldReturnCollectionsFromDatabase()
        {
            //Given
            Mongo db = new Mongo(string.Format("Server={0}:{1}", "localhost", "27017"));
            db.Connect();
            IMongoCollection collection = db["test"]["folks"];
            Document doc1 = new Document() { { "first_name", "Bill" }, { "middle_initial", "Q" }, { "last_name", "Jackson" }, { "address", "744 Nottingham St." } };
            Document doc2 = new Document() { { "first_name", "Ralph" }, { "middle_initial", "M" }, { "last_name", "Buckingham" }, { "state", "CA" } };
            Document doc3 = new Document() { { "first_name", "Ronald" }, { "middle_initial", "Q" }, { "last_name", "Weasly" }, { "city", "Santa Rosa" } };
            collection.Insert(doc1);
            collection.Insert(doc2);
            collection.Insert(doc3);
            var queryProvider = new MongoDbCSharpQuery();

            try
            {
                //When
                IList<string> collections = queryProvider.GetCollections("localhost", "test", "27017");

                //Then
                Assert.IsNotNull(collections.Where(c => c == "folks").SingleOrDefault());
            }
            finally
            {
                //Clean Up
                collection.Delete(doc1);
                collection.Delete(doc2);
                collection.Delete(doc3);
                queryProvider.Dispose();
            }
        }
开发者ID:nicklv,项目名称:MongoDB-Management-Studio,代码行数:31,代码来源:MongoDbCSharpTest.cs

示例14: ProjectionBuilder

 /// <summary>
 /// Initializes a new instance of the <see cref="MongoWhereClauseExpressionTreeVisitor"/> class.
 /// </summary>
 /// <param name="configuration">The configuration.</param>
 private ProjectionBuilder(IMappingStore mappingStore, ParameterExpression documentParameter)
 {
     this.mappingStore = mappingStore;
     this.resultObjectMappingParameter = documentParameter;
     this.fields = new Document();
     this.memberNames = new Stack<string>();
 }
开发者ID:andoco,项目名称:mongodb-csharp,代码行数:11,代码来源:ProjectionBuilder.cs

示例15: DocumentConstructorTest

 public void DocumentConstructorTest()
 {
     string key = string.Empty; // TODO: Initialize to an appropriate value
     object value = null; // TODO: Initialize to an appropriate value
     Document target = new Document(key, value);
     Assert.Inconclusive("TODO: Implement code to verify target");
 }
开发者ID:automatonic,项目名称:mongodb-net,代码行数:7,代码来源:DocumentTest.cs


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