Skip to main content

A Python module to interact with a MongoDB database via HTTP requests.

Project description

MongoDB Client

A Python module to interact with a MongoDB database via HTTP requests.

Features

  • Sign In: Authenticate using email and password to receive an access token.
  • CRUD Operations: Create, Read, Update, and Delete records in the MongoDB database.
  • Flexible Authentication: Use the access token for authentication in subsequent requests.

Installation

You can install this module directly from the GitHub repository:

pip install git+https://github.com/yourusername/mongodb_client.git

Usage

1. Import and Initialize the Client

First, import the MongoDB class from the module and initialize it with the base URL of your MongoDB HTTP server:

from mongodb_client.mongodb import MongoDB

client = MongoDB(base_url="http://localhost:8080")

2. Sign In

Sign in with your email and password to receive an access token:

success = client.signin("email@example.com", "password")
if success:
    print("Signed in successfully!")
else:
    print("Failed to sign in.")

3. Perform CRUD Operations

Get Records

Retrieve records from a specific database and collection:

records = client.get_records("mydatabase", "mycollection")
print(records)

Get Record by ID

Retrieve a specific record by its ID:

record = client.get_record_by_id("mydatabase", "mycollection", "record_id")
print(record)

Create Records

Create new records in a specific database and collection:

new_record = {"name": "John Doe", "email": "john@example.com"}
response = client.create_records("mydatabase", "mycollection", new_record)
print(response)

Update Record

Update an existing record by its ID:

updated_data = {"name": "Jane Doe"}
response = client.update_record("mydatabase", "mycollection", "record_id", updated_data)
print(response)

Delete Record

Delete a specific record by its ID:

response = client.delete_record("mydatabase", "mycollection", "record_id")
print(response)

Delete Records

Delete all records in a specific database and collection:

response = client.delete_records("mydatabase", "mycollection")
print(response)

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Project details


Release history Release notifications | RSS feed

This version

0.2

Download files

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

Source Distribution

mongodb_client-0.2.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

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

mongodb_client-0.2-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

Details for the file mongodb_client-0.2.tar.gz.

File metadata

  • Download URL: mongodb_client-0.2.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.7

File hashes

Hashes for mongodb_client-0.2.tar.gz
Algorithm Hash digest
SHA256 a5455b9404b88219f0ec095e9a14ff5a65a292f7c703f5c38fbd35bdab517317
MD5 fca78c1ca151605722fd50fd1e5ce4de
BLAKE2b-256 b52a22d7e32bfbacc5f23f4815b0db52b5845b64ac14c0008ef1c7d288ed466a

See more details on using hashes here.

File details

Details for the file mongodb_client-0.2-py3-none-any.whl.

File metadata

  • Download URL: mongodb_client-0.2-py3-none-any.whl
  • Upload date:
  • Size: 3.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.7

File hashes

Hashes for mongodb_client-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b56cacd794ab62bb5bc1621b25b1281908c105c9654feaf80961dc94dbc49848
MD5 6853a35d3f54e762d91c25cb6b68c8d2
BLAKE2b-256 6146af3a7e260de98dc539ecf97798b1adb4709f629c90c295d9b56885d67801

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