private void HandleCommand(string databaseName, string collectionName, BsonDocument document) { if (collectionName != "$cmd") { return; } if (document.Contains("dropIndexes")) { m_outlet.DeleteIndex(databaseName, document["dropIndexes"].ToString(), document["index"].ToString()); } else if (document.Contains("create")) { HandleCreateCollection(databaseName, document["create"].ToString(), document); } else if (document.Contains("drop")) { m_outlet.DeleteCollection(databaseName, document["drop"].ToString()); } else if (document.Contains("renameCollection")) { var oldNs = new OplogNamespace(document["renameCollection"]); var newNs = new OplogNamespace(document["to"]); m_outlet.RenameCollection(oldNs.DatabaseName, oldNs.CollectionName, newNs.CollectionName); } else if (document.Contains("dropDatabase")) { m_outlet.DeleteDatabase(databaseName); } else { // Unrecognized command } }
private void HandleCreateIndex(BsonDocument document) { var ns = new OplogNamespace(document["ns"]); if (document.Contains("v") && document["v"].ToInt32() != 1) { // Only v1 indexes are supported // ref: http://docs.mongodb.org/manual/tutorial/roll-back-to-v1.8-index/ return; } var key = document["key"].ToBsonDocument(); document.Remove("ns"); document.Remove("key"); document.Remove("_id"); m_outlet.CreateIndex(ns.DatabaseName, ns.CollectionName, key, document); }
private void HandleCommand(string databaseName, string collectionName, BsonDocument document) { if(collectionName != "$cmd") { return; } if(document.Contains("dropIndexes")) { m_outlet.DeleteIndex(databaseName, document["dropIndexes"].ToString(), document["index"].ToString()); } else if(document.Contains("create")) { HandleCreateCollection(databaseName, document["create"].ToString(), document); } else if(document.Contains("drop")) { m_outlet.DeleteCollection(databaseName, document["drop"].ToString()); } else if(document.Contains("renameCollection")) { var oldNs = new OplogNamespace(document["renameCollection"]); var newNs = new OplogNamespace(document["to"]); m_outlet.RenameCollection(oldNs.DatabaseName, oldNs.CollectionName, newNs.CollectionName); } else if(document.Contains("dropDatabase")) { m_outlet.DeleteDatabase(databaseName); } else { // Unrecognized command } }
private void HandleCreateIndex(BsonDocument document) { var ns = new OplogNamespace(document["ns"]); if(document.Contains("v") && document["v"].ToInt32() != 1) { // Only v1 indexes are supported // ref: http://docs.mongodb.org/manual/tutorial/roll-back-to-v1.8-index/ return; } var key = document["key"].ToBsonDocument(); document.Remove("ns"); document.Remove("key"); document.Remove("_id"); m_outlet.CreateIndex(ns.DatabaseName, ns.CollectionName, key, document); }