Skip to content

Tarik Billa

  • Web Development
    • html
    • vue.js
    • laravel
    • css
    • javascript
    • jquery
    • node.js
    • php
    • asp.net
  • Programming
    • python
    • java
    • c
    • c++
    • c#
  • git
  • android

pymongo

convert pymongo cursor to json

January 9, 2024 by Tarik

It looks like you want to import from bson not pymongo. I believe json_util was moved to that module recently. https://pymongo.readthedocs.io/en/stable/api/bson/json_util.html

Categories pymongo Tags pymongo Leave a comment

How to make pymongo’s find() return a list?

March 5, 2023 by Tarik

The following code will convert the entire result set (Cursor) into a list: myresults = list(mydb.mycollection.find()) This is fine for relatively small result sets, as you are pulling everything into memory.

Categories pymongo Tags pymongo Leave a comment

How to convert objectid to string

February 8, 2023 by Tarik

ObjectId.toString() and ObjectId.valueOf() are in Mongo JavaScript API. In Python API (with PyMongo) proper way is to use pythonic str(object_id) as you suggested in comment, see documentation on ObjectId.

Categories pymongo Tags objectid, pymongo Leave a comment

Tarik Billa

Software Engineer
tarikbilla@gmail.com
+8801884414000
  • Reuse a hash in YAMLApril 17, 2024
  • Dockerfile: how to redirect the output of a RUN command to a variable?April 16, 2024
  • How to cd to a directory with spaces in the directory name?April 16, 2024
  • Maximum MIME type length when storing the type in a databaseApril 16, 2024
  • What is the difference between Unit, Integration, Regression and Acceptance Testing?April 16, 2024
© 2026 Tarik Billa