MongoUtils
Some utils to deal with MongoDB more easily.
Connect to database
Simple function to connect to MongoDB or a specific database.
Connect to MongoDB server
from monutils import connect
from monutils import Mode
# Connect to localhost in the default port without authentication
client = connect()
# Connect to a host given
client = connect(host, port)
# Using replicaset
client = connect(host, port, replicaset)
# Connect to MongoDB using user and password
client = connect(host, port, replicaset, user, password)
# Without replicaset
client = connect(host, port, None, user, password)
client = connect(host, port, user=user, password=password)
# Select the authentication mechanism (if mode is not set, then it tries all possible authentication methods)
client = connect(host, port, replicaset, user, password, mode=Mode.SCRAM_SHA_256)
# Using certificates
client = connect(host, port, replicaset, user, password, cert_key_file, ca_file, mode=Mode.SCRAM_SHA_256)
# Using session token
client = connect(host, port, replicaset, user, password, session_token=token, mode=Mode.SCRAM_SHA_256)
Connect to MongoDB database
from monutils import connect_database
from monutils import Mode
# Connect to localhost in the default port without authentication
client = connect_database(databasse=database)
# Connect to a host given
client = connect_database(host, port, database=database)
# Using replicaset
client = connect_database(host, port, replicaset, database)
# Connect to MongoDB using user and password
client = connect_database(host, port, replicaset,
database, user, password)
# Without replicaset
client = connect_database(host, port, None, database, user, password)
client = connect_database(host, port,
database=database, user=user, password=password)
# Select the authentication mechanism
# (if mode is not set, then it tries all possible authentication methods)
client = connect_database(host, port, replicaset, database, user,
password, mode=Mode.SCRAM_SHA_256)
# Using certificates
client = connect_database(host, port, replicaset, database, user, password,
cert_key_file, ca_file, mode=Mode.SCRAM_SHA_256)
# Using session token
client = connect_database(host, port, replicaset, database, user, password,
session_token=token, mode=Mode.SCRAM_SHA_256)
Copy collections
You can copy collection from a database to another easily.
from monutils import copy
from_client = connect(...) # Connection with the source MongoDB server
to_client = connect(...) # Connection with the target MongoDB server
# Copy the collection
copy(from_client, to_client, from_db, to_db, from_collection, to_collection)
# Copy de collection ignoring copy errors
copy(from_client, to_client, from_db, to_db, from_collection, to_collection, True)
Create a cache mongodb database
from monutils import connect
from monutils.cache import MongoCache
client = connect(...)
db = client['my_db']
# Create a cache without storage limit
cache = MongoCache(db['my_collection'])
# Add an element to the collection
cache[key] = value
cache.add(key, value)
# Update an existing element to the collection
cache.update(key, value)
# Remove an element from the collection
cache.remove(key)
# Retrieve an element from the collection
cache[key]
# Check if the element is in the collection
key in cache
# Calculate the cache size
cache.size
# Create a cache limited to 1000 elements
cache = MongoCache(db['my_collection'], 1000)
Metadata
Release files for monutils 0.1.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| monutils-0.1.9.tar.gz | 8.8 kB | Without provenance | Details for monutils-0.1.9.tar.gz |
Release files / monutils-0.1.9.tar.gz
| Download URL | monutils-0.1.9.tar.gz |
|---|---|
| Size | 8.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
229dd1e09b3f3e94ee44939f863e0fb2b06c05b5dac7a453e318c63fe04bf865
|
|
BLAKE2b-256 checksum How to use checksums |
3e8a73c02029caff46bf362538120ceeb3c608ae5a816a762d7e66de80ea33cb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Security for monutils 0.1.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.