Giter Club home page Giter Club logo

mongolite's Introduction

mongolite

Lite mongodb engine in python

Run Tests BringThemBack


pip install pymongolite

Examples

simple

from pymongolite import MongoClient

with MongoClient(dirpath="~/my_db_dir", database="my_db") as client:
    db = client.get_default_database()
    collection = db.get_collection("users")

    collection.insert_one({"name": "yoyo"})
    collection.update_one({"name": "yoyo"}, {"$set": {"age": 20}})
    user = collection.find_one({"age": 20})
    print(user) # -> {"_id": ObjectId(...), "name": "yoyo", "age": 20}
from pymongolite import MongoClient

client = MongoClient(dirpath="~/my_db_dir", database="my_db")

db = client.get_default_database()
collection = db.get_collection("users")

collection.insert_one({"name": "yoyo"})
collection.update_one({"name": "yoyo"}, {"$set": {"age": 20}})
user = collection.find_one({"age": 20})
print(user) # -> {"_id": ObjectId(...), "name": "yoyo", "age": 20}

client.close()

Indexes

from pymongolite import MongoClient

client = MongoClient(dirpath="~/my_db_dir", database="my_db")

db = client.get_default_database()
collection = db.get_collection("users")

# Make query with name faster
collection.create_index({"name": 1})

collection.insert_one({"name": "yoyo"})
collection.update_one({"name": "yoyo"}, {"$set": {"age": 20}})
user = collection.find_one({"age": 20})
print(user) # -> {"_id": ObjectId(...), "name": "yoyo", "age": 20}

indexes = collection.get_indexes()
print(indexes)  # -> [{'id': UUID('8bb4cac8-ae52-4fff-9e69-9f36a99956cd'), 'field': 'age', 'type': 1, 'size': 1}]

client.close()

Support

The goal of this project is to create sqlite version for mongodb

For now the library is supporting:

actions:

  • database
    • create_database
    • get_database
    • drop_database
  • collection
    • create_collection
    • get_collection
    • drop_collection
    • get_collection_names
  • index
    • create_index
    • delete_index
    • get_indexes
  • document
    • insert_many / insert_one
    • update_many / update_one
    • find / find_one
    • replace_many / replace_one

filtering ops:

  • field matching
  • $eq / $ne
  • $gt / $gte
  • $lt / $lte
  • $not
  • $and / $or / $nor
  • $exists
  • $in / $nin

mutation ops:

  • $set
  • $unset
  • $inc
  • $addToSet
    • $each
  • $push
    • $each
    • $sort
    • $slice
  • $pull

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.