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