示例#1
0
        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
            }
        }
示例#2
0
        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);
        }
示例#3
0
        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
            }
        }
示例#4
0
        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);
        }