Cosmos Doc Manager takes MongoDB documents and makes them available in Azure Cosmos DB following the format specified by Mongo Connector. It piggybacks on Mongo Replica Set Oplog and is intended for near-realtime synchronizations. Currently it works for Cosmos DB SQL API. Partial MongoDB updates are handled with Stored Procedures and support the following operations.
The software in this repository is provided AS IS, with no guarantees of any kind. This project is an independent effort and is NOT associated with Microsoft. Having said that, Pull Requests are most welcome.
- You must have Python installed. Python 3 is recommended.
Mongo Connector
operates on a MongoReplica Set
.Docker
is the easiest way to spin it up locally.- For local testing, install Azure Cosmos DB Emulator. Cosmos DB Emulator currently only supports SQL API.
Run this to spin up a volume-mounted, single-node Mongo Replica Set
;
docker run -it --rm -p 27017:27017 -v $HOME/mongodb:/data mongo --replSet myreplicaset
Replica Set
needs to be initialized and re-configured because by default Mongo assigns container's inner address as host
. Run this from Mongo Shell;
rs.initiate();
conf = rs.conf();
conf.members[0].host = '127.0.0.1:27017';
rs.reconfig(conf, {force:true});
- Install Mongo Connector
sudo pip install mongo-connector
- Clone this repo
git clone https://github.com/syedhassaanahmed/cosmos_doc_manager.git
- Let Mongo Connector locate our Doc Manager
cd cosmos_doc_manager && export PYTHONPATH=.
- Disable
HTTPS
Certificate warningexport PYTHONWARNINGS="ignore:Unverified HTTPS request"
mongo-connector -c config.json
Mongo Connector
's custom configuration is specified here.
Below JSON is an example config file to sync data in Graph format with Cosmos DB Emulator.
{
"mainAddress": "localhost:27017",
"docManagers": [
{
"docManager": "cosmos_doc_manager",
"targetURL": "https://localhost:8081",
"bulkSize": 100,
"args": {
"masterKey": "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="
}
}
]
}
- Support for partitioned collections
- Support for other Cosmos DB APIs