當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。