Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
@api_view(['POST'])
def csv(request):
client = pymongo.MongoClient("mongodb://localhost:27017")
# Select the database
db = client["ApexLubrication"]
# Select the collection
collection = db["apex_ml_conveyor_notes"]
# Define the index field (adjust as needed)
index_field = "_id" # Assuming _id field is indexed
# Create an aggregation pipeline to count indexed documents
pipeline = [
{"$match": {index_field: {"$exists": True}}}, # Match documents with the indexed field
{"$group": {"_id": None, "count": {"$sum": 1}}} # Count matching documents
]
# Execute the aggregation pipeline
result = list(collection.aggregate(pipeline))
# Calculate the estimated total count
estimated_total = result[0]["count"] if result else 0
# Close the connection
total_records = estimated_total # collection.count_documents({}) # Get the total record count
batch_size = 1000000 # Adjust batch size as needed
num_batches = (total_records // batch_size) + 1
with Pool(processes=4) as pool: # Adjust the number of processes as needed
pool.map(export_batch, range(num_batches))
client.close()
print(f"Estimated Total Count: {estimated_total}")
return JsonResponse({"success":estimated_total})
def export_batch(batch_num):
batch_size = 1000000 # Adjust batch size as needed
skip = batch_num * batch_size
cursor = collection.find({}).skip(skip).limit(batch_size)
csv_file_path = 'apex_ml_conveyor_notes.csv' # Use a single CSV file
with open(csv_file_path, 'a', newline='') as csvfile: # Append mode
fieldnames = ['_id',
'factory_id',
'dcu_id',
'conveyor_id',
'FLAG_apex',
'username_id',
'note',
'entered_at',
'DCUDateTime',
'created_at',
'updated_at']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
# Write the header row only once
if skip == 0:
writer.writeheader()
for document in cursor:
# Write the document
writer.writerow(document)
# total_records = estimated_total # collection.count_documents({}) # Get the total record count
# batch_size = 1000000 # Adjust batch size as needed
# num_batches = (total_records // batch_size) + 1
#
# with Pool(processes=4) as pool: # Adjust the number of processes as needed
# pool.map(export_batch, range(num_batches))
# Close MongoDB connection
client.close()
![]() |
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team