### Installing JSONLite via pip Source: https://github.com/simpx/jsonlite/blob/main/README.md This snippet demonstrates how to install the JSONLite library using pip, the Python package installer. It's a standard command-line installation process that fetches the package from PyPI. ```sh pip install jsonlite ``` -------------------------------- ### JSONLite Data File Structure Example Source: https://github.com/simpx/jsonlite/blob/main/README.md This JSON snippet illustrates the typical data layout within a JSONLite database file. It shows an array of objects under a 'data' key, where each object represents a document and includes an '_id' field along with other user-defined data fields. ```json { "data": [ { "_id": 1, "name": "Alice", "age": 30 }, { "_id": 2, "name": "Bob", "age": 25 }, { "_id": 3, "name": "Charlie", "age": 20 } ] } ``` -------------------------------- ### Initializing JSONLite Database in Python Source: https://github.com/simpx/jsonlite/blob/main/README.md This Python snippet shows how to initialize a JSONLite database instance by importing the `JSONlite` class and creating an object. The constructor takes the desired JSON file name as an argument, which will be used for data storage. ```python from jsonlite import JSONlite db = JSONlite('mydatabase.json') ``` -------------------------------- ### Patching PyMongo to Use JSONLite in Python Source: https://github.com/simpx/jsonlite/blob/main/README.md This Python snippet shows how to patch the `pymongo` library to use JSONLite as its backend, allowing interaction with local JSON files using the familiar `pymongo` API. It demonstrates connecting to a 'jsonlite://' URI and performing operations like `insert_one` and `drop` as if interacting with a MongoDB instance. ```python from jsonlite import pymongo_patch pymongo_patch() from pymongo import MongoClient client = MongoClient('jsonlite://database') db = client.test_database collection = db.test_collection insert_result = collection.insert_one({"name": "Alice", "age": 30}) # Just like using pymongo collection.drop() ``` -------------------------------- ### Finding a Single Document with JSONLite in Python Source: https://github.com/simpx/jsonlite/blob/main/README.md This Python snippet shows how to retrieve a single document from the JSONLite database using the `find_one` method, based on a query criteria. It returns the first matching document as a dictionary or `None` if no document matches the criteria. ```python document = db.find_one({"name": "John Doe"}) document ``` -------------------------------- ### Finding Multiple Documents with JSONLite in Python Source: https://github.com/simpx/jsonlite/blob/main/README.md This Python snippet demonstrates how to query and retrieve multiple documents from the JSONLite database using the `find` method. It supports MongoDB-like query operators, such as `$gte` (greater than or equal to), to filter documents based on specified conditions. ```python documents = db.find({"age": {"$gte": 25}}) documents ``` -------------------------------- ### Inserting a Single Document with JSONLite in Python Source: https://github.com/simpx/jsonlite/blob/main/README.md This Python snippet demonstrates how to insert a single document into the JSONLite database using the `insert_one` method. It takes a dictionary representing the document and returns a result object containing the `inserted_id` of the newly added document. ```python result = db.insert_one({"name": "John Doe", "age": 30}) result.inserted_id ``` -------------------------------- ### Updating a Single Document with JSONLite in Python Source: https://github.com/simpx/jsonlite/blob/main/README.md This Python snippet illustrates updating a single document in the JSONLite database using the `update_one` method. It takes a query to identify the document and an update operation (e.g., `$set`) to modify its fields, returning counts of matched and modified documents. ```python result = db.update_one({"name": "John Doe"}, {"$set": {"age": 31}}) result.matched_count, result.modified_count ``` -------------------------------- ### Inserting Multiple Documents with JSONLite in Python Source: https://github.com/simpx/jsonlite/blob/main/README.md This Python snippet illustrates inserting multiple documents into the JSONLite database using the `insert_many` method. It accepts a list of dictionaries, each representing a document, and returns a result object with a list of `inserted_ids` for all added documents. ```python result = db.insert_many([ {"name": "Jane Doe", "age": 25}, {"name": "Alice", "age": 28} ]) result.inserted_ids ``` -------------------------------- ### Updating Multiple Documents with JSONLite in Python Source: https://github.com/simpx/jsonlite/blob/main/README.md This Python snippet shows how to update multiple documents in the JSONLite database using the `update_many` method. It applies the specified update operation to all documents that match the provided query criteria, returning the counts of matched and modified documents. ```python result = db.update_many({"age": {"$gte": 25}}, {"$set": {"status": "active"}}) result.matched_count, result.modified_count ``` -------------------------------- ### Deleting a Single Document with JSONLite in Python Source: https://github.com/simpx/jsonlite/blob/main/README.md This Python snippet demonstrates how to delete a single document from the JSONLite database using the `delete_one` method based on a query. It returns a result object containing the `deleted_count`, indicating how many documents were removed. ```python result = db.delete_one({"name": "John Doe"}) result.deleted_count ``` -------------------------------- ### Deleting Multiple Documents with JSONLite in Python Source: https://github.com/simpx/jsonlite/blob/main/README.md This Python snippet illustrates how to delete multiple documents from the JSONLite database using the `delete_many` method. It removes all documents that match the specified query criteria, returning the total `deleted_count`. ```python result = db.delete_many({"age": {"$lt": 30}}) result.deleted_count ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.