-
-
Save soltrinox/ee3b56f3f34af3312ed87c45066c2758 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from algoliasearch import algoliasearch | |
import pymongo | |
from pymongo import MongoClient | |
import json | |
client = algoliasearch.Client("Your_Application_ID", 'Your_API_Key') | |
index = client.init_index('Experiment_1') | |
MONGODB_URL1 = 'Your_MongoDB_Connection_String' | |
def move_collection(from_collection): | |
MONGODB_URL1 = 'Your_MongoDB_URL' | |
client_temp = pymongo.MongoClient( | |
MONGODB_URL1, | |
ssl=False | |
) | |
source_db = from_collection.split('.')[0] | |
source_collection = from_collection.split('.')[1] | |
xxx = range(0,client_temp[source_db][source_collection].count_documents({}),2000) | |
client_temp.close() | |
print(str(xxx)) | |
for batch in xxx: | |
MONGODB_URL1 = 'Your_MongoDB_Connection_String' | |
client = pymongo.MongoClient( | |
MONGODB_URL1, | |
ssl=False | |
) | |
source = client[source_db][source_collection] | |
int(batch) | |
list_view_objects = source.find({Your_MongoDb_Query}).skip(batch).limit(2000) | |
for i in list(list_view_objects): | |
print(type(i)) | |
index.add_object(i) | |
def main(): | |
from_collection ="Your_MongoDB_Database.Your_MongoDB_Collection" | |
move_collection(from_collection) | |
if __name__ == '__main__': main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment