Skip to main content

A simple MongoDB python driver

Project description

Logo MongoFire

A simple MongoDB python driver

Key Features

  • Easy MongoDB Queries: Simplify querying MongoDB by providing an intuitive and straightforward interface, making it as simple as working with Firestore.
  • Streamlined Updates and Deletions: Perform updates and deletions on MongoDB collections with ease, reducing the complexity of modifying data.

Installation

pip3 install mongofire

Usage

You need first to initialize the client in your main.py file.

from mongofire import MongoFire
MongoFire.initialize('mongodb://localhost:27017/')

And then you can use it on any file in your project like this

from mongofire import MongoDB
db = MongoDB('myAppDatabase')

Set a document

To create or overwrite a single document, use the following example:

data = {
    'name': 'Mohamed',
    'age': 20,
}

db.collection('users').document('my_custom_uid').set(data)

If the document does not exist, it will be created. If the document does exist, its contents will be overwritten with the newly provided data, unless you specify that the data should be merged into the existing document, as follows:

doc_ref = db.collection('users').document('my_custom_uid')

doc_ref.set({'gender': 'male'}, merge=True)

Update a document

If you want to update any field in the document, you can use the update method. You can increment values, push or pull items from the list, rename fields, and more.

from mongofire import Field, FieldValue
db.collection('users').document('my_uid').update({
    'name': Field.rename('username'),
    'age': FieldValue.increment(1),
})

Add a document

Sometimes the document id doesn't make sense and it's ok to be random in that case you can use the add method instead of the set method.

doc_ref = db.collection('users').add({
    'name': 'Max',
    'age': 30,
})

You can get the randomly generated id by doc_ref.id.

Delete a document

Delete any document as follows:

db.collection('users').document('doc_id').delete()

Documentation

If you want to know how to delete or update multiple documents or delve into the lib, read the full documentation at mongofire.readthedocs.io.

Contributing

We welcome contributions from the community. To contribute to the library, please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Make your changes, including tests and documentation.
  4. Run the test suite to ensure everything is working correctly.
  5. Submit a pull request.

License

The library is licensed under the MIT License. See the LICENSE file for more details.

Credits

  • Firestore: Firestore provided inspiration with its simplicity and productivity. Although not directly used as a dependency, it influenced the development of this library.
  • MongoDB: MongoDB served as the solution to build something similar to Firestore that is free and open source for all.

Support

If you have any questions, issues, or suggestions, please open an issue on the GitHub repository or contact the maintainer at pshteam.developers@gmail.com.

Changelog

  • v1.0.0 (2023-05-25): first release.

Roadmap

  • Sub Collection: add sub collcetions for documents.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mongofire-0.0.1.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mongofire-0.0.1-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file mongofire-0.0.1.tar.gz.

File metadata

  • Download URL: mongofire-0.0.1.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.4

File hashes

Hashes for mongofire-0.0.1.tar.gz
Algorithm Hash digest
SHA256 61e8f17be162dbacc9e926d2f75264305ea44a2368729a97c47d2527120bea8a
MD5 aecc82c94e6472cdd4bfa1b5de10f4b5
BLAKE2b-256 8de7fcfa41cc21514570b82f53a25fdb3b050069e4cbd7be43c52279279cdcf9

See more details on using hashes here.

File details

Details for the file mongofire-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: mongofire-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.4

File hashes

Hashes for mongofire-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 416bbd914b1e89c675406d30ac0c6c7324420f7d3ab605e52ee29ca68c7e75d6
MD5 52583a941b75338bbbdeabf4ba708469
BLAKE2b-256 50095b926b1ab1ae08397a3596203849ad683340d139af4f5cbc699707741903

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page