コード例 #1
0
 public MongoItem2()
 {
     this.id           = Guid.NewGuid().ToString("D");
     this.Location     = new GeoJsonPoint <GeoJson2DGeographicCoordinates>(new GeoJson2DGeographicCoordinates(48.080, 16.140));
     this.dateUploaded = DateTime.Now;
     this.DValue       = 3.2;
     this.LValue       = 4;
     this.TValue       = new BsonTimestamp(MongoItem2.ToUnixTime(DateTime.Now));
     this.AValue       = new string[] { "Hallo", "Welt", "wie", "gehts?" };
     this.Buffer       = new byte[] { 12, 13, 51, 6, 225, 121, 122 };
 }
コード例 #2
0
        public static async Task DemoMongoAPIDataTypes()
        {
            MongoClient client = MongoDemo.Client;
            var         db     = client.GetDatabase("demodb");

            try { await db.DropCollectionAsync("democol"); } catch (Exception) { }
            var col = db.GetCollection <MongoItem2>("democol");

            MongoItem2 item = new MongoItem2();

            col.InsertOne(item);

            // This query only works with a original MongoDB (f.e. Bitnami Instance) but not with CosmosDB
            try
            {
                var filter = "{ LValue: {$type: 18} }"; /// { "LValue":{$type: 18} }
                await col.Find(filter)
                .ForEachAsync(document => Console.WriteLine(document.LValue));

                filter = "{ DValue:{$type: 1} }"; /// { "DValue":{$type: 1} }
                await col.Find(filter)
                .ForEachAsync(document => Console.WriteLine(document.DValue));
            }
            catch (MongoCommandException ex)
            {
                Console.WriteLine($"Type query failed {ex.Result}.");
            }

            //var result = from items in col.AsQueryable<MongoItem2>()
            //             where items.DValue is Double
            //             select items;
            //foreach (var i in result)
            //{
            //    Console.WriteLine(i.DValue );
            //}
        }