Python MongoDB CRUD
Project description
Python Package for MongoDB CRUD
For use:
- Install package with PIP;
- Import from mongocrud Mongocrud;
- Configure database settings (location, collection, port...);
- Call object CRUD operations;
Example:
- For INSERT operation in database:
from mongocrud import MongoCRUD, ObjectId
from datetime import datetime
dbclients = MongoCRUD("mongodb://localhost","mongoteste1")
dbclients.insert("clients", {"_id": "12345", "name":"Anderson 1", "dtupdate": datetime.now()})
dbclients.insert("clients", {"_id": 15 , "name":"Anderson 2", "dtupdate": datetime.now()})
dbclients.insert("clients", {"name":"Anderson 3", "dtupdate": datetime.now()})
dbclients.insert("clients", {"name":"Anderson 4", "dtupdate": datetime.now()})
dbclients.insert("clients", {"name":"Anderson 5", "dtupdate": datetime.now()})
#12 bits/24 bits info as _id
dbclients.insert("clients", {"_id": ObjectId(b'000000000001'), "name":"Anderson 6", "dtupdate": datetime.now()})
- For SELECT operation on database (using orderby and direction for sort information):
from mongocrud import MongoCRUD
from datetime import datetime
dbclients = MongoCRUD("mongodb://localhost","mongoteste1")
clients_ordered = dbclients.select("clients", orderby="dtupdate", direction=1)
for client in clients_ordered: print(client)
- For SELECT BY _id (select if using ObjectId on _id):
from mongocrud import MongoCRUD
from datetime import datetime
dbclients = MongoCRUD("mongodb://localhost","mongoteste1")
clients = dbclients.select_by_id("clients", "12345", is_objectid=False)
print(clients)
clients = dbclients.select_by_id("clients", 15, is_objectid=False)
print(clients)
clients = dbclients.select_by_id("clients", "64495d9c140992e498f5fcb2", is_objectid=True)
print(clients)
- For DELETE query in database:
from mongocrud import MongoCRUD
from datetime import datetime
dbclients = MongoCRUD("mongodb://localhost","mongoteste1")
items = dbclients.delete("clients", {"name": "Anderson 2"})
print("QTD items deleted => ", items)
- For DELETE BY _id:
from mongocrud import MongoCRUD, ObjectId
from datetime import datetime
dbclients = MongoCRUD("mongodb://localhost","mongoteste1")
items = dbclients.delete_by_id("clients", "12345", is_objectid=False)
print("QTD items deleted => ", items)
items = dbclients.delete_by_id("clients", "64495d9c140992e498f5fcb1", is_objectid=True)
print("QTD items deleted => ", items)
items = dbclients.delete_by_id("clients", ObjectId(b"000000000001"), is_objectid=False)
print("QTD items deleted => ", items)
- for UPDATE row:
from mongocrud import MongoCRUD
from datetime import datetime
dbclients = MongoCRUD("mongodb://localhost","mongoteste1")
dbclients.update_one("clients", "12345", {"name": "teste1", "dtupdate": datetime.now()}, is_objectid=False)
dbclients.update_one("clients", "64496373fe1ef021a556b446", {"name": "teste2", "dtupdate": datetime.now()}, is_objectid=True)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mongo_malbizer-1.0.1.tar.gz
(3.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mongo_malbizer-1.0.1.tar.gz.
File metadata
- Download URL: mongo_malbizer-1.0.1.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff99563587056142cd5425af66d62a47e00c18a642c90d87eeab2126d8382836
|
|
| MD5 |
224b0c2fb367ffb9ef6280ae0eb5ec17
|
|
| BLAKE2b-256 |
804e91fc6389d5858197596a6e0b396ebfe98a2eb7967221aad5d39516cc2b5a
|
File details
Details for the file mongo_malbizer-1.0.1-py3-none-any.whl.
File metadata
- Download URL: mongo_malbizer-1.0.1-py3-none-any.whl
- Upload date:
- Size: 3.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35b109b4c150737a5793dabcc4298c2ee2fbe48595e4a077b0dfa76fb4abccb7
|
|
| MD5 |
23c85c2799ac864b5a2d709b05cf528f
|
|
| BLAKE2b-256 |
8d9c2aaac01353b4243ee9eb0cafc274f5f2cbf17d49a96fed4b1b8a45ec7f62
|