コード例 #1
0
        /// <summary>
        /// Shows the behaviour of CosmosDB when access with Linq for MongoDB driver
        /// in contrary to a standard mongodb instantiated via Bitnami as virtual machine f.e.
        /// </summary>
        /// <returns></returns>
        public static async Task DemoMongoAPIQueries2()
        {
            try
            {
                MongoClient client = MongoDemo.Client;
                var         db     = client.GetDatabase("demodb");
                try
                {
                    await db.DropCollectionAsync("democol");
                }
                catch (Exception)
                {
                }
                var            col       = db.GetCollection <MongoItem>("democol");
                MongoQueryTest queryTest = new MongoQueryTest();
                await queryTest.AddItemsToMongoDBCollection(col, queryTest.CreateTestData());

                queryTest.TestExpressionQueries(col, col.AsQueryable <MongoItem>());
            }
            catch (Exception ex)
            {
                Console.WriteLine($"QueryDemoMongoAPI Demo failed with {ex.Message}.");
                throw;
            }
        }
コード例 #2
0
        /// <summary>
        /// This stores a document into CosmosDB. First the document is stored with the
        /// DocumentDB-API and then with the MongoAPI. Explore both Location-Elements:
        ///  * "LocationMongoDB" and
        ///  * "LocationCosmosDB"
        ///  and their representation in the database.
        /// </summary>
        /// <returns></returns>
        public static async Task DemoStorageOfLocation()
        {
            try
            {
                MongoItem demoDoc = new MongoItem("Hansi", "Huber", "Test", "ModeT", "",
                                                  1.1, 2.2,
                                                  new string[] { "male", "person" },
                                                  new string[] { "hansi" });
                // =======================================================
                // Store in CosmosDB
                // =======================================================
                DocumentClient docDBclient = await CosDB.ConnectToCosmosDB(Config.Account_DemoBuild_Mongo, Config.Account_DemoBuild_Mongo_Key);

                Database docDBdb = await CosDB.CreateOrGetDatabase(docDBclient, "demodb");

                DocumentCollection collection = await CosDB.CreateOrGetCollection(docDBclient, docDBdb, "democolDocDB", 400, null, null, false);

                await docDBclient.CreateDocumentAsync(collection.SelfLink, demoDoc);

                // =======================================================
                // Store with MongoDB API
                // =======================================================
                MongoQueryTest queryTest = new MongoQueryTest();
                MongoClient    client    = MongoDemo.Client;
                var            db        = client.GetDatabase("demodb");
                try
                {
                    await db.DropCollectionAsync("democol");
                }
                catch (Exception)
                {
                }
                var col = db.GetCollection <MongoItem>("democol");
                await col.InsertOneAsync(demoDoc);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"DemoMongoAPILocation Demo failed with {ex.Message}.");
                throw;
            }
        }