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


C# BsonDocument.zToJson方法代码示例

本文整理汇总了C#中BsonDocument.zToJson方法的典型用法代码示例。如果您正苦于以下问题:C# BsonDocument.zToJson方法的具体用法?C# BsonDocument.zToJson怎么用?C# BsonDocument.zToJson使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BsonDocument的用法示例。


在下文中一共展示了BsonDocument.zToJson方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TransfertOldLastId

 public static void TransfertOldLastId(string fromCollection, string fromDatabase, string toCollection = null, string toDatabase = null, string IdGeneratorCollection = "IdGenerator", string fromServer = null, string toServer = null)
 {
     if (toCollection == null)
         toCollection = fromCollection;
     if (toDatabase == null)
         toDatabase = fromDatabase;
     Trace.WriteLine("transfert last id from collection \"{0}\" last id collection \"{1}\" database \"{2}\" server \"{3}\" to collection \"{4}\" database \"{5}\" server \"{6}\"",
         IdGeneratorCollection, fromCollection, fromDatabase, fromServer, toCollection, toDatabase, toServer);
     MongoCollection collection = zmongo.GetCollection(fromDatabase, IdGeneratorCollection, fromServer);
     if (!collection.Exists())
         throw new PBException("collection not found \"{0}\" database \"{1}\" server \"{2}\"", IdGeneratorCollection, fromDatabase, fromServer);
     BsonDocument doc = collection.FindOneAs<BsonDocument>(new QueryDocument { { "collection", fromCollection } });
     if (doc == null)
         throw new PBException("last id not found for collection \"{0}\"", fromCollection);
     int lastId = doc["lastId"].AsInt32;
     collection = zmongo.GetCollection(toDatabase, toCollection, toServer);
     doc = collection.FindOneAs<BsonDocument>(new QueryDocument { { "_id", 0 } });
     if (doc != null)
         throw new PBException("document _id 0 exists already in collection \"{0}\" database \"{1}\" server \"{2}\"", toCollection, toDatabase, toServer);
     doc = new BsonDocument { { "_id", 0 }, { "LastId", lastId } };
     WriteConcernResult result = collection.Insert(doc);
     if (result.Ok)
     {
         Trace.WriteLine("last id transfered to collection \"{0}\" database \"{1}\" server \"{2}\"", toCollection, toDatabase, toServer);
         Trace.WriteLine(doc.zToJson());
     }
     else
         throw new PBException("unknow error inserting last id to collection \"{0}\" database \"{1}\" server \"{2}\"", toCollection, toDatabase, toServer);
 }
开发者ID:labeuze,项目名称:source,代码行数:29,代码来源:MongoIdGenerator_v2.cs


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