skip to Main Content

Get amount of objects saved in MongoDB using Pymongo

I'm trying to get amount of objects saved in MongoDB with db = myclient.database_sample my_collection = db["database"] mydoc = my_collection.find().count() print("The number of documents in collection : ", mydoc) but I'm getting an error mydoc = my_collection.find().count() AttributeError: 'Cursor' object…

VIEW QUESTION

Get last document in MongoDB collection

I am trying to get the last document in a MongoDB collection. The following works in the Mongo shell: db.collection.find().limit(1).sort({$natural:-1}) Results in the last object like so: { "_id" : ObjectId("62c8817075c9400469b1fc3a"), "token" : "135e53ebb05aa2b6055513843cb8e0dca1", "createdAt" : ISODate("2022-07-08T19:11:44.730Z"), "updatedAt" : ISODate("2022-07-08T19:11:44.730Z"),…

VIEW QUESTION
Back To Top
Search