Skip to main content

A wrapper library on top of pymongo.

  pip install mongoy

Connecting to Database

   from mongoy.mongo import Mongo

   connection = 'mongodb://127.0.0.1:27017'
   db_name = 'mydb''

   mgy = Mongo(connection, db_name)

Get pymongo db instance

  # get pymongo db instance
  db = mgy.get_db()

Register a collection for operations

   # Register a collection for CRUD data ops

   mgy.register_collection('users')
  # Add a document
  doc = {
    'name': 'test',
    'age': 10,
  }

  result = mgy.users.insert(doc)


  # Add multiple documents
  docs = [{
    'name': 'testuser',
    'age': 21
  }, {
    'name': 'testy',
    'age': 22
  }, {
    'name': 'uwoo',
    'age': 27
  }]

  result = mgy.users.insert(docs)
  # Find Documents

  result = mgy.users.find()

  age_22_users = mgy.users.find({
    'age': 22
  })

  others = mgy.users.find({
    'age': {'$ne': 22}
  })

  mgy.users.find({
    '_id': result[0]['_id']
  })
  from bson.objectid import ObjectId
  id = ObjectId('some-mongo-id')

  # Update single document 
  mgy.users.find_one_and_update({'_id': id}, {'$set': {'age': 30}})

  # Update all matching documents
  mgy.users.find_all_and_update({'age': {'$lt': 25}}, {'$set': {'age': 30}})

  # Insert if not exists 
  mgy.users.find_one_and_update({'_id': id}, {'$set': {'age': 30}}, upsert=True)
  # Delete Single Documents
  mgy.users.delete({
    'age': 22
  })

   # Delete all matching Documents
  mgy.users.delete({
    'age': 22
  }, all=True)

Release files for mongoy 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mongoy 0.1.5
File Size Uploaded
mongoy-0.1.5.tar.gz 3.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mongoy 0.1.5
File Interpreter ABI Platform
mongoy-0.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 7.2 kB

Release files / mongoy-0.1.5.tar.gz

Download URL mongoy-0.1.5.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
1f79f55688f52e8062aceebacb6ac8a5304d447690a5bbbe0b3091a09ec7b9b8
BLAKE2b-256 checksum
How to use checksums
6ea2ac653d4cf50be8694bf48d8eef5eeaa6e0c38c2f7e9a1536a924e125674d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.2

Release files / mongoy-0.1.5-py3-none-any.whl

Download URL mongoy-0.1.5-py3-none-any.whl
Size 3.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
456c0d9f7cb91b5e601ba3e20766be0299c46271788c4a1b461243c494b0504e
BLAKE2b-256 checksum
How to use checksums
1c77155eee6b8a9647351db7f2d4fe8fc1e11a9e7a8dcfbdfee21374e7fda90f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.2

Release history Release notifications | RSS feed

This release

0.1.5 This release

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page