http://blog.sina.com.cn/s/blog_927f3c2401011937.html 图形工具

http://api.mongodb.org/csharp/current/html/R_Project_CSharpDriverDocs.htm C#API

http://docs.mongodb.org/manual/reference/method/  Shell命令

http://docs.mongodb.org/manual/ MongoDB官方文档

http://blog.michaelckennedy.net/2013/04/08/optimistic-concurrency-in-mongodb-using-net-and-csharp/ MongoDB.Kennedy

https://mongodb-documentation.readthedocs.org/en/latest/ecosystem/tutorial/serialize-documents-with-the-csharp-driver.html   Serialize Documents with the CSharp Driver(使用c#对实体进行序列化)

https://www.mongodb.com/thank-you/download/mongodb-enterprise 官网下载地址

http://www.ttlsa.com/mms/follow-me-to-use-mongodb-mms-services/ 随我来使用mongodb mms服务

当类体结构改变,删除了某个属性,或者某个属性的类型发生了改变?

1、属性的类型发生了改变

 public class Address { public ObjectId Id; public string ZipCode; }

 public class ZipCodeSerializer : BsonBaseSerializer { public override object Deserialize(BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options) { var bsonType = bsonReader.CurrentBsonType; switch (bsonType) { case BsonType.Null: bsonReader.ReadNull(); return null; case BsonType.String: return bsonReader.ReadString(); case BsonType.Int32: return bsonReader.ReadInt32().ToString(); default: var message = string.Format("ZipCodeSerializer expects to find a String or an Int32, not a {0}.", bsonType); throw new BsonSerializationException(message); } } public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options) { if (value == null) { bsonWriter.WriteNull(); } else { bsonWriter.WriteString((string)value); } } }

 BsonClassMap.RegisterClassMap<Address>(cm => { cm.AutoMap(); cm.GetMemberMap(a => a.ZipCode).SetSerializer(new ZipCodeSerializer()); });
 

2、删除了某个属性

 var allDocuments = collectionToUpdate .FindAll();foreach(var document in allDocuments ){var oldFieldValue = document ["OldFieldName"];if(!document.Contains("NewFieldName")) document.Add("NewFieldName", oldFieldValue); document.Remove("OldFieldName"); collectionToUpdate.Save(document);}

 3、使用newtonsoft.json转换为json

 class ObjectId Converter:JsonConverter{publicoverridevoidWriteJson(JsonWriter writer,object value,JsonSerializer serializer){ serializer.Serialize(writer, value.ToString());}publicoverrideobjectReadJson(JsonReader reader,Type objectType,object existingValue,JsonSerializer serializer){thrownewNotImplementedException();}publicoverride bool CanConvert(Type objectType){returntypeof(ObjectId).IsAssignableFrom(objectType);//return true;}}

         public class ObjectIdConverter : TypeConverter

         {

             public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)

             {

                 if (sourceType == typeof(string))

                 {

                     return true;

                 }

                 return base.CanConvertFrom(context, sourceType);

             }

             public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)

             {

                 if (value is string)

                     return ObjectId.Parse((string)value);

                 return base.ConvertFrom(context, culture, value);

             }

             // Overrides the ConvertTo method of TypeConverter.

             public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)

             {

                 if (destinationType == typeof(string))

                 {

                     return ((ObjectId)value).ToString();

                 }

                 return base.ConvertTo(context, culture, value, destinationType);

             }

         }
 

使用:[TypeConverter(typeof(ObjectIdConverter))]

4、实体中排除某些字段,不写入到集合中

publicclassMyClass{ [BsonIgnore]publicstringSomeProperty{get;set;}}

或者使用初始化代码的形式,设置映射关系

BsonClassMap.RegisterClassMap<MyClass>(cm=>{cm.AutoMap();cm.UnmapProperty(c=>c.SomeProperty);});

5、在连接参数中设置用户名和密码

http://docs.mongodb.org/ecosystem/tutorial/authenticate-with-csharp-driver/

6、mongodb中时间为当前小时数 减 8

分       析:存储在mongodb中的时间是标准时间UTC +0:00 而咱们中国的失去是+8.00 。

解决方法:在datetime属性上增加特性

[BsonDateTimeOptions(Kind = DateTimeKind.Local)]

public DateTime Birth{get;set;}

MangoDB在C#中的使用的更多相关文章

  1. 明确MangoDB在企业中应用

    目录 1.MongoDB是什么? 2.为什么要用MongoDB? 3.主要特性 4.C/S服务模型 5.完善的命令行工具 6.几个shell实操 7.在Java中使用MongoDB 明确MongoDB ...

  2. Python开源框架

    info:更多Django信息url:https://www.oschina.net/p/djangodetail: Django 是 Python 编程语言驱动的一个开源模型-视图-控制器(MVC) ...

  3. NoSQL--couchdb

    Couchdb CouchDB是Apache组织发布的一款开源的.面向文档类型的NoSQL数据库.由Erlang编写,使用json格式保存数据.CouchDB以RESTful的格式提供服务可以很方便的 ...

  4. 在centos中安装mangodb

    1.下载完安装包,并解压 tgz(以下演示的是 64 位 Linux上的安装) curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_6 ...

  5. c#操作MangoDB 之MangoDB CSharp Driver驱动详解

    序言 MangoDB CSharp Driver是c#操作mongodb的官方驱动. 官方Api文档:http://api.mongodb.org/csharp/2.2/html/R_Project_ ...

  6. centos5.5下mangodb启动报错glibc

    mangodb启动报错glibc找不到(centos5.5) 报错形式 [root@test-172-16-0-139-ip mongodb-server]# /data/mongodb-server ...

  7. 在.Net Core中使用MongoDB的入门教程(一)

    首先,我们在MongoDB的官方文档中看到,MongoDb的2.4以上的For .Net的驱动是支持.Net Core 2.0的. 所以,在我们安装好了MangoDB后,就可以开始MangoDB的.N ...

  8. Asp.Net Core中使用MongoDB的入门教程,控制台程序使用 MongoDB

    内容来源  https://blog.csdn.net/only_yu_yy/article/details/78882446 首先,创建一个.Net Core的控制台应用程序.然后使用NuGet导入 ...

  9. 非关系统型数据库-mangodb

    第三十六课 非关系统型数据库-mangodb 目录 二十四 mongodb介绍 二十五 mongodb安装 二十六 连接mongodb 二十七 mongodb用户管理 二十八 mongodb创建集合. ...

随机推荐

  1. 【转】使用Scanner输入字符串时next()和nextLine()区别

    在实现字符窗口的输入时,很多人更喜欢选择使用扫描器Scanner,它操作起来比较简单.在编程的过程中,我发现用Scanner实现字符串的输入有两种方法,一种是next(),一种nextLine(),但 ...

  2. Java 之 反射机制

    反射:框架设计的灵魂 框架:是一个可以供我们使用的半成品软件.可以在框架的基础上进行软件开发,简化编码. 反射:将类的各个组成部分封装为其他对象,这就是反射机制. 好处: 1. 可以在程序运行过程中, ...

  3. fastjson反序列化漏洞研究(上)

    前言 最近护网期间,又听说fastjson传出“0day”,但网上并没有预警,在github上fastjson库中也有人提问关于fastjson反序列化漏洞的详情.也有人说是可能出现了新的绕过方式.不 ...

  4. SVN上传本地项目到服务器

    1. 在服务器新建一个文件夹目录: 2. 将新建的目录在本地check out下来: 3. 将自己的项目拷贝到check out下来的文件夹下: 4. 右键点击svnàAdd,选择所有添加: 5. 右 ...

  5. Elasticsearch7

    elasticsearch 由来 点击进入 elasticsearch 基本概念 点击进入 elasticsearch 安装 点击进入 elasticsearch 增删改查 点击进入 elastics ...

  6. 每日一题-——LeetCode(78)子集

    给定一组不含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集).输入: nums = [1,2,3]输出:[ [3],  [1],  [2],  [1,2,3],  [1,3],  [2, ...

  7. 运维开发笔记整理-template的使用

    运维开发笔记整理-Django的template的使用 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 在上一篇博客中我们学习了HttpResponse 和JsonResponse方 ...

  8. CentOS6和7启动流程

    CentOS6启动流程 https://linux.cn/article-8807-1.html BIOS 开机自检,硬件自检 MBR MBR磁盘分区是一种使用最为广泛的分区结构,它也被称为DOS分区 ...

  9. go 变量的定义方式

    var a int a = 1 var a,b int a =1 b = 2 var a,b = 1,2 var s string = "hello world" a, b := ...

  10. C语言入坑指南-缓冲区溢出

    前言 缓冲区溢出通常指的是向缓冲区写入了超过缓冲区所能保存的最大数据量的数据.如果说之前所提到的一些问题可能只是影响部分功能的实现,那么缓冲区溢出将可能会造成程序运行终止,被不安全代码攻击等严重问题, ...