Skip to main content
Help us improve PyPI by participating in user testing. All experience levels needed!

Mango: simple MongoDb wrapper

Project description

A Simple wrapper module for Mongo sit on top of PyMongo.

Installation

To install mango lib: pip install python-mango.

Usage

To import module: import mango.

Sample:

import mango

uri = "mongodb://user:pwd@localhost:port/database"
mango.init_db(uri)

# To get database object
db = mango.mgdb

# To get table object
mytable = mango.get_table('mytable')

# Select rows
rows = mango.select('mytable')
rows = mango.select('mytable', { "qty": { "$gt": 4 } })

# Insert
mango.insert('mytable', dict(name='Aung Aung'))

# Update
_filter = dict(id=1234)
_value = dict(mark=80)
mango.update('mytable', _filter, _value)

_value = {
    "$set": {
        "name": "Tun Aung"
    },
    "$push": {
        "marks": {
            "english": 60
        }
    }
}
mango.update('mytable', _filter, _value)

# Delete
_filter = dict(id=456)
mango.delete('mytable', _filter)

init_db

To initialize MongoDb Connection.

Parameter:

uri: MongoDb URI

get_table

Get the MongoDb Table object.

Parameter:

  • table_name: Table name

select

Query record(s) from table.

Parameters:

  • table_name: Table name
  • _filter: MongoDb filter object
  • is_many: Use find or find_one. Default is False which means find_one will be used.
  • **kwargs: KwArgs which will be pass to pymongo function

insert

Insert record(s) to table.

Parameters:

  • table_name: Table name
  • _value: Value that will be inserted
  • is_many: insert_one or insert_many. Default is False (means insert_one).
  • **kwargs: KwArgs will be pass to pymongo function

update

Update record(s) to table.

Parameters:

  • table_name: Table name
  • _filter: MongoDb filter object
  • _value: Value that will be updated
  • is_many: update_one or update_many. Default is False (means update_one).
  • _operation: MongoDb update operation. Default is $set.
  • **kwargs: KwArgs will be pass to pymongo function.

delete

Delete record(s) to table.

Parameters:

  • table_name: Table name
  • _filter: MongoDb filter object
  • is_many: delete_one or delete_many. Default is False (means delete_one).
  • **kwargs: KwArgs will be pass to pymongo function.

Project details


Release history Release notifications

This version
History Node

0.1.7

History Node

0.1.6

History Node

0.1.5

History Node

0.1.4

History Node

0.1.3

History Node

0.1.2

History Node

0.1.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
python_mango-0.1.7-py2.py3-none-any.whl (5.2 kB) Copy SHA256 hash SHA256 Wheel py2.py3 Feb 17, 2017
python-mango-0.1.7.tar.gz (3.6 kB) Copy SHA256 hash SHA256 Source None Feb 17, 2017

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page