15 lines
506 B
Python
15 lines
506 B
Python
def create_insert_many_command(input_file: str, output_file: str):
|
|
with open(input_file, 'r', encoding='utf-8') as file:
|
|
words = file.readlines()
|
|
|
|
formatted_words = [f" {{ word: '{word.strip()}' }}" for word in words]
|
|
command = "db.words.insertMany([\n" + ",\n".join(formatted_words) + "\n]);"
|
|
|
|
with open(output_file, 'w', encoding='utf-8') as file:
|
|
file.write(command)
|
|
|
|
input_file = 'words.txt'
|
|
output_file = 'out.txt'
|
|
|
|
create_insert_many_command(input_file, output_file)
|