1. Home
  2. Docs
  3. MiStats
  4. Data import

Data import

Data migration with MongoDB

In order to migrate from Viewstats to MiStats, you must:

  • Download script migrate_from_viewstats.py from the operator's personal account
  • After downloading, transfer the file to the folder /usr/share/microimpuls/mistats/backend/
  • Fill in the variables inside the migration script for example below:
#BD name in Mongo
MONGODB_NAME="smarty"
#host MongoDB
MONGODB_HOST="127.0.0.1"
Port MongoDB
MONGODB_PORT = 27017
# the name of the collection with viewing data in MongoDB
MONGODB_COLLECTION="reports"
the size of one portion of records when transferring data (if MongoDB falls on a timeout, you can reduce the volume of this portion)
MONGO_LIMIT=100,000
  • Download the PyMongo Python Library:
pip install pymongo
  • Start data migration with the command:
sudo python migrate_from_viewstats.py --copy --database=smarty_stats

Additional parameters of the team:

  • -copy — option to copy data from MongoDB to ClickHouse
  • --database — option to specify which ClickHouse database to transfer data to
  • -delete — removes the database in ClickHouse. It only works with option --databaseIgnoring other options. Required to re-import data from MongoDB to ClickHouse.
  • - count — displays the amount of data in MongoDB. You may need to change the variable MONGO_LIMIT scripted migrate_from_viewstats.py
  • -client_id — option to specify Client ID (to be able to import or count data for a particular client_id, rather than all at once). Useful when Smarty has multiple clients