Skip to main content

SoraDBlite is a Python class designed to simplify interactions with MongoDB databases, the operation of SoraDBlite is similar to the pymongo. It is also a lite version of pymongo.Added Sora AI integration for error detection and solution.

Project description

SoraDBlite

Python Versions SoraDBlite latest Version

๐ŸŒ contact me:

Telegram

About

SoraDBlite is a Python class designed to simplify interactions with MongoDB databases. And the operation are similar to the mongodb, and it is easy to understand. It is just a lite version of mongodb. It providing the interface for performing essential CRUD (Create, Read, Update, Delete) operations. With SoraDBlite, developers can easily manage and manipulate data within their MongoDB collections, making it ideal for both simple and complex database tasks.

SoraDefaultDB is a easy Database Testing. SoraDefaultDB is a tool for designed to test the functionality of SoraDBlite. You don't need to input MongoDB URI and password, just specify the collection name. After testing, drop the collections you created to ensure they are removed from the database.

Key Features:

โ—˜ Easy Connection Management: Simplifies connecting to MongoDB databases.

โ—˜ CRUD Operations: Perform basic CRUD operations effortlessly.

  • Insert single or multiple documents.

  • Find single or multiple documents with flexible query options.

  • Update single or multiple documents.

  • Delete single or multiple documents.

  • Collection Management: Drop collections with ease.

โ—˜ Sorting Capabilities: Sort documents by specified fields in ascending or descending order.

โ—˜ Error Handling: Custom exceptions for better error.

โ—˜ Sora AI integration: For error detection and solution.

โ—˜ SoraDBlite updatation: A function fetches the latest SoraDBlite version from PyPI and upgrades the local installation using pip.

How to get db url and collection

Video Tutorial

For a detailed video tutorial, check out this link: video

Differences Between pymongo and SoraDBlite

Feature pymongo SoraDBlite
Library Type Low-level MongoDB driver High-level wrapper for pymongo
Usage Directly interacts with MongoDB Simplified methods for common operations
Flexibility Complete control over MongoDB operations Abstracts complexity, less granular control
Error Handling Developers implement their own error handling Built-in error handling
Code Complexity More complex and verbose User-friendly and concise

Important

๐ˆ๐ฆ๐ฉ๐จ๐ซ๐ญ๐š๐ง๐ญ Use SoraDefaultDB to quickly test the database setup with just a collection name. Use SoraDBlite for your main project, Don't use the SoraDefaultDB in your main project.

If you create a collection using SoraDefaultDB, remember to drop it after testing to avoid unnecessary data accumulation. Verify that the collection has been removed by checking the database.

import SoraDefaultDB
from SoraDefaultDB import SoraDBLiteError, SoraDefaultDB, is_collection_available

db_collection = "your_db_collection_name"

db = SoraDefaultDB()

db.connect(db_collection)
# your code
db.drop_collection("your_db_collection_name")

is_collection_available(db_collection) # Pass the db_collection_name only

Installation

Make sure you have SoraDBlite installed. You can install it using pip if you haven't already:

pip install SoraDBlite

Usage of SoraDBlite

๐—ฆ๐—ผ๐—ฟ๐—ฎ๐——๐—•๐—น๐—ถ๐˜๐—ฒ

Importing the Library

import SoraDBlite
from SoraDBlite import SoraDBlite, SoraDBLiteError, is_collection_available, sora_ai, get_all_collection, update_SoraDBlite

Updating the latest version through local installation using pip

import SoraDBlite
from SoraDBlite import update_SoraDBlite 

update_SoraDBlite() #pip install --upgrade SoraDBlite==latest_version

Get all collection

import SoraDBlite
from SoraDBlite import SoraDBlite, SoraDBLiteError, get_all_collection

db_url = "your_mongodb_url"
db_password = "your_db_password"

get_all_collection(db_url, db_password)

Checking the collection name is available or not

import SoraDBlite
from SoraDBlite import SoraDBlite, SoraDBLiteError, is_collection_available
db_url = "your_mongodb_url"
db_password = "your_db_password"
db_collection = "your_db_collection_name"

is_collection_available(db_url, db_password, db_collection) # Pass the db_url, db_pass, db_collection_name

Importing the Exception class

import SoraDBlite
from SoraDBlite import SoraDBlite, SoraDBLiteError

db_url = "your_mongodb_url"
db_password = "your_db_password"
db_collection = "your_db_collection_name"

db = SoraDBlite()

try:
   db.connect(db_url, db_password, db_collection)
except SoraDBLiteError as e:
   print(e)

Importing the Exception Class and Using sora_ai()

Sora_ai() will given how to solve the error/ give the solution.

import SoraDBlite
from SoraDBlite import SoraDBlite, SoraDBLiteError, sora_ai

db_url = "your_mongodb_url"
db_password = "your_db_password"
db_collection = "your_db_collection_name"

db = SoraDBlite()

try:
   db.connect(db_url, db_password, db_collection)
except SoraDBLiteError as e:
   print(e)
   sora_ai(e) # Pass the error message to sora_ai() for a solution

Connecting to the Database

To connect to your MongoDB database, use the connect method:

import SoraDBlite
from SoraDBlite import SoraDBlite, SoraDBLiteError

db_url = "your_mongodb_url"
db_password = "your_db_password"
db_collection = "your_db_collection_name"

db = SoraDBlite()
db.connect(db_url, db_password, db_collection)

Inserting Documents

Insert a single document:

import SoraDBlite
from SoraDBlite import SoraDBlite, SoraDBLiteError

db_url = "your_mongodb_url"
db_password = "your_db_password"
db_collection = "your_db_collection_name"

db = SoraDBlite()
db.connect(db_url, db_password, db_collection)

document = {"name": "Alice", "age": 30, "city": "New York"}
inserted_id = db.insert_one(document)
print("Inserted document with ID:", inserted_id)

Insert multiple documents:

import SoraDBlite
from SoraDBlite import SoraDBlite, SoraDBLiteError

db_url = "your_mongodb_url"
db_password = "your_db_password"
db_collection = "your_db_collection_name"

db = SoraDBlite()
db.connect(db_url, db_password, db_collection)

documents = [
    {"name": "Alice", "age": 30, "city": "New York"},
    {"name": "Bob", "age": 25, "city": "Los Angeles"},
    {"name": "Charlie", "age": 35, "city": "Chicago"}
]
inserted_ids = db.insert_many(documents)
print("Inserted document IDs:", inserted_ids)

Finding Documents

Find a single document:

import SoraDBlite
from SoraDBlite import SoraDBlite, SoraDBLiteError

db_url = "your_mongodb_url"
db_password = "your_db_password"
db_collection = "your_db_collection_name"

db = SoraDBlite()
db.connect(db_url, db_password, db_collection)

query = {"name": "Alice"}
result = db.find_one(query)
print("Found document:", result)

Find multiple documents:

import SoraDBlite
from SoraDBlite import SoraDBlite, SoraDBLiteError

db_url = "your_mongodb_url"
db_password = "your_db_password"
db_collection = "your_db_collection_name"

db = SoraDBlite()
db.connect(db_url, db_password, db_collection)

query = {"age": {"$gt": 25}}
results = db.find_many(query)
print("Found documents:", results)

Updating Documents

Update a single document:

import SoraDBlite
from SoraDBlite import SoraDBlite, SoraDBLiteError

db_url = "your_mongodb_url"
db_password = "your_db_password"
db_collection = "your_db_collection_name"

db = SoraDBlite()
db.connect(db_url, db_password, db_collection)

filter = {"name": "Alice"}
update = {"$set": {"city": "Los Angeles"}}
updated_count = db.update_one(filter, update)
print("Updated documents:", updated_count)

Update multiple documents:

import SoraDBlite
from SoraDBlite import SoraDBlite, SoraDBLiteError

db_url = "your_mongodb_url"
db_password = "your_db_password"
db_collection = "your_db_collection_name"

db = SoraDBlite()
db.connect(db_url, db_password, db_collection)

filter = {"city": "New York"}
update = {"$set": {"city": "New York City"}}
updated_count = db.update_many(filter, update)
print("Updated documents:", updated_count)

Deleting Documents

Delete a single document:

import SoraDBlite
from SoraDBlite import SoraDBlite, SoraDBLiteError

db_url = "your_mongodb_url"
db_password = "your_db_password"
db_collection = "your_db_collection_name"

db = SoraDBlite()
db.connect(db_url, db_password, db_collection)

filter = {"name": "Alice"}
deleted_count = db.delete_one(filter)
print("Deleted documents:", deleted_count)

Delete multiple documents:

import SoraDBlite
from SoraDBlite import SoraDBlite, SoraDBLiteError

db_url = "your_mongodb_url"
db_password = "your_db_password"
db_collection = "your_db_collection_name"

db = SoraDBlite()
db.connect(db_url, db_password, db_collection)

filter = {"age": {"$lt": 25}}
deleted_count = db.delete_many(filter)
print("Deleted documents:", deleted_count)

Sorting Documents

Sort documents by a field in ascending order:

import SoraDBlite
from SoraDBlite import SoraDBlite, SoraDBLiteError

db_url = "your_mongodb_url"
db_password = "your_db_password"
db_collection = "your_db_collection_name"

db = SoraDBlite()
db.connect(db_url, db_password, db_collection)

results = db.sort_by("age", True)
print("Sorted by age (ascending):", results)

Sort documents by a field in descending order:

import SoraDBlite
from SoraDBlite import SoraDBlite, SoraDBLiteError

db_url = "your_mongodb_url"
db_password = "your_db_password"
db_collection = "your_db_collection_name"

db = SoraDBlite()
db.connect(db_url, db_password, db_collection)

results = db.sort_by("name", False)
print("Sorted by name (descending):", results)

Dropping a Collection

To drop a collection, use the drop_collection method:

import SoraDBlite
from SoraDBlite import SoraDBlite, SoraDBLiteError, is_collection_available

db_url = "your_mongodb_url"
db_password = "your_db_password"
db_collection = "your_db_collection_name"

db = SoraDBlite()
db.connect(db_url, db_password, db_collection)

db.drop_collection("your_db_collection_name")

is_collection_available(db_url, db_password, db_collection) # Pass the db_url, db_pass, db_collection_name

counting the documents

Get the count of the documents:

import SoraDBlite
from SoraDBlite import SoraDBlite, SoraDBLiteError

db_url = "your_mongodb_url"
db_password = "your_db_password"
db_collection = "your_db_collection_name"

db = SoraDBlite()
db.connect(db_url, db_password, db_collection)

count = db.count({"name":"Alice"})
print(count)

Fetch all values

Fetch all values for a specific key name:

import SoraDBlite
from SoraDBlite import SoraDBlite, SoraDBLiteError

db_url = "your_mongodb_url"
db_password = "your_db_password"
db_collection = "your_db_collection_name"

db = SoraDBlite()
db.connect(db_url, db_password, db_collection)

d=db.fetch_values_by_key("name")
print(d)

Get the version

Get the version of pymongo and soradb:

import SoraDBlite
from SoraDBlite import SoraDBlite, SoraDBLiteError

db_url = "your_mongodb_url"
db_password = "your_db_password"
db_collection = "your_db_collection_name"

db = SoraDBlite()
db.connect(db_url, db_password, db_collection)

db.version()

Example Code

import SoraDBlite
from SoraDBlite import SoraDBlite, SoraDBLiteError

db_url = "your_mongodb_url"
db_password = "your_db_password"
db_collection = "your_db_collection_name"

db = SoraDBlite()
db.connect(db_url, db_password, db_collection)

# Insert a document
document = {"name": "Alice", "age": 30, "city": "New York"}
inserted_id = db.insert_one(document)
print("Inserted document with ID:", inserted_id)

# Find a document
query = {"name": "Alice"}
result = db.find_one(query)
print("Found document:", result)

# Find multiple documents
query = {"age": {"$gt": 25}}
results = db.find_many(query)
print("Found documents:", results)

# Update a document
filter = {"name": "Alice"}
update = {"$set": {"city": "Los Angeles"}}
updated_count = db.update_one(filter, update)
print("Updated documents:", updated_count)

# Delete a document
filter = {"name": "Alice"}
deleted_count = db.delete_one(filter)
print("Deleted documents:", deleted_count)

# Insert multiple documents
documents = [
    {"name": "Alice", "age": 30, "city": "New York"},
    {"name": "Bob", "age": 25, "city": "Los Angeles"},
    {"name": "Charlie", "age": 35, "city": "Chicago"}
]
inserted_ids = db.insert_many(documents)
print("Inserted document IDs:", inserted_ids)

# Find multiple documents
query = {"age": {"$gt": 25}}
results = db.find_many(query)
print("Found documents:", results)

# Update multiple documents
filter = {"city": "New York"}
update = {"$set": {"city": "New York City"}}
updated_count = db.update_many(filter, update)
print("Updated documents:", updated_count)

# Delete multiple documents
filter = {"age": {"$lt": 25}}
deleted_count = db.delete_many(filter)
print("Deleted documents:", deleted_count)

# Sort documents by age
results = db.sort_by("age", True)
print("Sorted by age (ascending):", results)

# Sort documents by name
results = db.sort_by("name", False)
print("Sorted by name (descending):", results)

# Count the documents
count = db.count({"name":"Alice"})
print(count)

# Fetch all values for a specific key
d = db.fetch_values_by_key("name")
print(d)

#Get the version of pymongo and soradb
db.version()

# Drop a collection
db.drop_collection(db_collection)

# Check the collection is dropped or not
is_collection_available(db_url, db_password, db_collection) # Pass the db_url, db_pass, db_collection_name

Usage of SoraDefaultDB

๐—ฆ๐—ผ๐—ฟ๐—ฎ๐——๐—ฒ๐—ณ๐—ฎ๐˜‚๐—น๐˜๐——๐—•

Importing the Library

import SoraDefaultDB
from SoraDefaultDB import SoraDefaultDB, SoraDBLiteError, is_collection_available, sora_ai, update_SoraDBlite

Checking the collection name

import SoraDefaultDB
from SoraDefaultDB import SoraDefaultDB, SoraDBLiteError, is_collection_available

db_collection = "your_db_collection_name"

is_collection_available(db_collection) # Pass the db_collection_name only 

Updating the latest version through local installation using pip

import SoraDefaultDB
from SoraDefaultDB import update_SoraDBlite 

update_SoraDBlite() #pip install --upgrade SoraDBlite==latest_version

Importing the Exception class

import SoraDefaultDB
from SoraDefaultDB import SoraDefaultDB, SoraDBLiteError

db_collection = "your_db_collection_name"

db = SoraDefaultDB()

try:
   db.connect(db_collection)
except SoraDBLiteError as e:
   print(e)

Importing the Exception Class and Using sora_ai()

Sora_ai() will given how to solve the error/ give the solution.

import SoraDefaultDB
from SoraDefaultDB import SoraDefaultDB, SoraDBLiteError, sora_ai

db_collection = "your_db_collection_name"

db = SoraDefaultDB()

try:
   db.connect(db_collection)
except SoraDBLiteError as e:
   print(e)
   sora_ai(e) # Pass the error message to sora_ai() for a solution

Connecting to the Database

To connect to your MongoDB database, use the connect method:

import SoraDefaultDB
from SoraDefaultDB import SoraDefaultDB, SoraDBLiteError

db_collection = "your_db_collection_name"

db = SoraDefaultDB()

db.connect(db_collection)

Inserting Documents

Insert a single document:

import SoraDefaultDB
from SoraDefaultDB import SoraDefaultDB, SoraDBLiteError

db_collection = "your_db_collection_name"

db = SoraDefaultDB()

db.connect(db_collection)

document = {"name": "Alice", "age": 30, "city": "New York"}
inserted_id = db.insert_one(document)
print("Inserted document with ID:", inserted_id)

Insert multiple documents:

import SoraDefaultDB
from SoraDefaultDB import SoraDefaultDB, SoraDBLiteError

db_collection = "your_db_collection_name"

db = SoraDefaultDB()

db.connect(db_collection)

documents = [
    {"name": "Alice", "age": 30, "city": "New York"},
    {"name": "Bob", "age": 25, "city": "Los Angeles"},
    {"name": "Charlie", "age": 35, "city": "Chicago"}
]
inserted_ids = db.insert_many(documents)
print("Inserted document IDs:", inserted_ids)

Finding Documents

Find a single document:

import SoraDefaultDB
from SoraDefaultDB import SoraDefaultDB, SoraDBLiteError

db_collection = "your_db_collection_name"

db = SoraDefaultDB()

db.connect(db_collection)

query = {"name": "Alice"}
result = db.find_one(query)
print("Found document:", result)

Find multiple documents:

import SoraDefaultDB
from SoraDefaultDB import SoraDefaultDB, SoraDBLiteError

db_collection = "your_db_collection_name"

db = SoraDefaultDB()

db.connect(db_collection)

query = {"age": {"$gt": 25}}
results = db.find_many(query)
print("Found documents:", results)

Updating Documents

Update a single document:

import SoraDefaultDB
from SoraDefaultDB import SoraDefaultDB, SoraDBLiteError

db_collection = "your_db_collection_name"

db = SoraDefaultDB()

db.connect(db_collection)

filter = {"name": "Alice"}
update = {"$set": {"city": "Los Angeles"}}
updated_count = db.update_one(filter, update)
print("Updated documents:", updated_count)

Update multiple documents:

import SoraDefaultDB
from SoraDefaultDB import SoraDefaultDB, SoraDBLiteError

db_collection = "your_db_collection_name"

db = SoraDefaultDB()

db.connect(db_collection)
filter = {"city": "New York"}
update = {"$set": {"city": "New York City"}}
updated_count = db.update_many(filter, update)
print("Updated documents:", updated_count)

Deleting Documents

Delete a single document:

import SoraDefaultDB
from SoraDefaultDB import SoraDefaultDB, SoraDBLiteError, SoraDBLiteError

db_collection = "your_db_collection_name"

db = SoraDefaultDB()

db.connect(db_collection)
filter = {"name": "Alice"}
deleted_count = db.delete_one(filter)
print("Deleted documents:", deleted_count)

Delete multiple documents:

import SoraDefaultDB
from SoraDefaultDB import SoraDefaultDB, SoraDBLiteError, SoraDBLiteError

db_collection = "your_db_collection_name"

db = SoraDefaultDB()

db.connect(db_collection)

filter = {"age": {"$lt": 25}}
deleted_count = db.delete_many(filter)
print("Deleted documents:", deleted_count)

Sorting Documents

Sort documents by a field in ascending order:

import SoraDefaultDB
from SoraDefaultDB import SoraDefaultDB, SoraDBLiteError, SoraDBLiteError

db_collection = "your_db_collection_name"

db = SoraDefaultDB()

db.connect(db_collection)
results = db.sort_by("age", True)
print("Sorted by age (ascending):", results)

Sort documents by a field in descending order:

import SoraDefaultDB
from SoraDefaultDB import SoraDefaultDB, SoraDBLiteError, SoraDBLiteError

db_collection = "your_db_collection_name"

db = SoraDefaultDB()

db.connect(db_collection)

results = db.sort_by("name", False)
print("Sorted by name (descending):", results)

Dropping a Collection

To drop a collection, use the drop_collection method:

import SoraDefaultDB
from SoraDefaultDB import SoraDefaultDB, SoraDBLiteError, is_collection_available

db_collection = "your_db_collection_name"

db = SoraDefaultDB()

db.connect(db_collection)

db.drop_collection("your_db_collection_name")

is_collection_available(db_collection) # Pass the db_collection_name only

counting the documents

Get the count of the documents:

import SoraDefaultDB
from SoraDefaultDB import SoraDefaultDB, SoraDBLiteError

db_collection = "your_db_collection_name"

db = SoraDefaultDB()

db.connect(db_collection)

count = db.count({"name":"Alice"})
print(count)

Fetch all values

Fetch all values for a specific key name:

import SoraDefaultDB
from SoraDefaultDB import SoraDefaultDB, SoraDBLiteError

db_collection = "your_db_collection_name"

db = SoraDefaultDB()

db.connect(db_collection)

d=db.fetch_values_by_key("name")
print(d)

Get the version

Get the version of pymongo and soradb:

import SoraDefaultDB
from SoraDefaultDB import SoraDefaultDB, SoraDBLiteError

db_collection = "your_db_collection_name"

db = SoraDefaultDB()

db.connect(db_collection)

db.version()

Example Code

import SoraDefaultDB
from SoraDefaultDB import SoraDefaultDB, SoraDBLiteError, is_collection_available

db_collection = "your_db_collection_name"

db = SoraDefaultDB()

db.connect(db_collection)

# Insert a document
document = {"name": "Alice", "age": 30, "city": "New York"}
inserted_id = db.insert_one(document)
print("Inserted document with ID:", inserted_id)

# Find a document
query = {"name": "Alice"}
result = db.find_one(query)
print("Found document:", result)

# Find multiple documents
query = {"age": {"$gt": 25}}
results = db.find_many(query)
print("Found documents:", results)

# Update a document
filter = {"name": "Alice"}
update = {"$set": {"city": "Los Angeles"}}
updated_count = db.update_one(filter, update)
print("Updated documents:", updated_count)

# Delete a document
filter = {"name": "Alice"}
deleted_count = db.delete_one(filter)
print("Deleted documents:", deleted_count)

# Insert multiple documents
documents = [
    {"name": "Alice", "age": 30, "city": "New York"},
    {"name": "Bob", "age": 25, "city": "Los Angeles"},
    {"name": "Charlie", "age": 35, "city": "Chicago"}
]
inserted_ids = db.insert_many(documents)
print("Inserted document IDs:", inserted_ids)

# Find multiple documents
query = {"age": {"$gt": 25}}
results = db.find_many(query)
print("Found documents:", results)

# Update multiple documents
filter = {"city": "New York"}
update = {"$set": {"city": "New York City"}}
updated_count = db.update_many(filter, update)
print("Updated documents:", updated_count)

# Delete multiple documents
filter = {"age": {"$lt": 25}}
deleted_count = db.delete_many(filter)
print("Deleted documents:", deleted_count)

# Sort documents by age
results = db.sort_by("age", True)
print("Sorted by age (ascending):", results)

# Sort documents by name
results = db.sort_by("name", False)
print("Sorted by name (descending):", results)

# Count the documents
count = db.count({"name":"Alice"})
print(count)

# Fetch all values for a specific key
d = db.fetch_values_by_key("name")
print(d)

#Get the version of pymongo and soradb
db.version()

# Drop a collection
db.drop_collection(db_collection)

# Check the collection is dropped or not
is_collection_available(db_collection)

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

SoraDBlite-2.0.16.tar.gz (26.7 kB view details)

Uploaded Source

Built Distribution

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

SoraDBlite-2.0.16-py3-none-any.whl (23.5 kB view details)

Uploaded Python 3

File details

Details for the file SoraDBlite-2.0.16.tar.gz.

File metadata

  • Download URL: SoraDBlite-2.0.16.tar.gz
  • Upload date:
  • Size: 26.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.13

File hashes

Hashes for SoraDBlite-2.0.16.tar.gz
Algorithm Hash digest
SHA256 06965013508b2d04a43cf436d8f8d1a11a48d096b4553de0fece96e4884887e6
MD5 c615f00843a218ddf1f59a403691fabb
BLAKE2b-256 c71bd3fc157d51148cbb0d92bdd4e01b71d7c9b49968f2908e9c750d920527ff

See more details on using hashes here.

File details

Details for the file SoraDBlite-2.0.16-py3-none-any.whl.

File metadata

  • Download URL: SoraDBlite-2.0.16-py3-none-any.whl
  • Upload date:
  • Size: 23.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.13

File hashes

Hashes for SoraDBlite-2.0.16-py3-none-any.whl
Algorithm Hash digest
SHA256 3fc2dc78062972e7f4d31ac061d939615361df610858c8a76c9c4d07e02ea435
MD5 057ff10d58982dc97d5bcc38bcec75c2
BLAKE2b-256 83e6226001c23ba5b0dbe636b4cc31f0ec945d4c35f0de8c65005d287523f43f

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