本文整理匯總了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);
}