public void LogUpdate(MongoCollection collection, QueryDocument query, UpdateDocument update, UpdateFlags flags) { if (_writeToFile == null) { return; } _writeToFile.Write("{0:yyyy-MM-dd HH:mm:ss.ffffff} ", DateTime.Now); _writeToFile.Write("Update : {0} query ", collection.zGetFullName()); _writeToFile.Write(query.ToJson()); _writeToFile.Write(" update "); _writeToFile.Write(update.ToJson()); _writeToFile.Write(" flags "); _writeToFile.Write(flags.ToString()); }
//IEnumerable<TValue> Distinct<TValue>(string key, IMongoQuery query); //public static MongoCursor<TDocument> Find<TDocument>(string databaseName, string collectionName, string query, string sort = null, string fields = null, int limit = 0, string options = null, string server = null) //{ //} public static void FindAndModify(string databaseName, string collectionName, string query, string update, bool upsert = false, string sort = null, string fields = null, string server = null) { MongoCollection collection = MongoCommand.GetDatabase(server, databaseName).GetCollection(collectionName); QueryDocument queryDoc = query.zToQueryDocument(); UpdateDocument updateDoc = update.zToUpdateDocument(); Trace.Write("FindAndModify : {0} query ", collection.zGetFullName()); Trace.Write(queryDoc.ToJson()); Trace.Write(" update "); Trace.Write(updateDoc.ToJson()); Trace.Write(" upsert {0}", upsert); SortByWrapper sortByWrapper = null; if (sort != null) { sortByWrapper = sort.zToSortByWrapper(); Trace.Write(" sort {0}", sortByWrapper.ToJson()); } FieldsWrapper fieldsWrapper = null; if (fields != null) { fieldsWrapper = fields.zToFieldsWrapper(); Trace.Write(" fields {0}", fieldsWrapper.ToJson()); } FindAndModifyResult result; try { result = collection.zFindAndModify(queryDoc, updateDoc, upsert, sortByWrapper, fieldsWrapper); TraceResult(result); } finally { Trace.WriteLine(); } Trace.WriteLine("document"); Trace.WriteLine(result.ModifiedDocument.zToJson()); }
public void LogFindAndModify(MongoCollection collection, QueryDocument query, UpdateDocument update, bool upsert, SortByWrapper sort, FieldsWrapper fields) { if (_writeToFile == null) { return; } _writeToFile.Write("{0:yyyy-MM-dd HH:mm:ss.ffffff} ", DateTime.Now); _writeToFile.Write("FindAndModify : {0}", collection.zGetFullName()); _writeToFile.Write(" query {0}", query.ToJson()); _writeToFile.Write(" update "); _writeToFile.Write(update.ToJson()); _writeToFile.Write(" upsert {0}", upsert); if (sort != null) { _writeToFile.Write(" sort {0}", sort.ToJson()); } if (fields != null) { _writeToFile.Write(" fields {0}", fields.ToJson()); } //_log.WriteLine(); }
public static void Update(string databaseName, string collectionName, string query, string update, UpdateFlags flags = UpdateFlags.None, string server = null) { MongoCollection collection = MongoCommand.GetDatabase(server, databaseName).GetCollection(collectionName); QueryDocument queryDoc = query.zToQueryDocument(); UpdateDocument updateDoc = update.zToUpdateDocument(); Trace.Write("Update : {0} query ", collection.zGetFullName()); Trace.Write(queryDoc.ToJson()); Trace.Write(" update "); Trace.Write(updateDoc.ToJson()); Trace.Write(" flags "); Trace.Write(flags.ToString()); try { WriteConcernResult result = collection.zUpdate(queryDoc, updateDoc, flags); TraceResult(result); } finally { Trace.WriteLine(); } }