Skip to main content

MongoDB client for CPython and MicroPython.

It has mongo Shell like APIs.

Requirement

Install

CPython

$ python3 -m pip install nmongo

MicroPython

$ micropython -m upip install micropython-errno
$ micropython -m upip install micropython-os
$ micropython -m upip install micropython-time
$ micropython -m upip install micropython-datetime
$ micropython -m upip install micropython-binascii
$ micropython -m upip install micropython-random
$ micropython -m upip install nmongo

Example

Connect to Database

>>> import nmongo
>>> db = nmongo.connect('servername', 'somewhatdatabase')
>>>

Create

>>> db.fruits.insert({'name': 'apple', 'price': 200})
1
>>> db.fruits.insert([{'name': 'orange', 'price': 100}, {'name': 'banana', 'price': 50}])
2
>>> db.fruits.count()
3
>>>

Read

>>> cur = db.fruits.find({'name': 'banana'})
>>> cur.fetchone()
{'price': 50, '_id': ObjectId("5826b2313d28909ce9f6ea63"), 'name': 'banana'}
>>> cur = db.fruits.find()
>>> cur.fetchall()
[{'price': 200, '_id': ObjectId("5826b2273d28909ce9f6ea61"), 'name': 'apple'}, {'price': 100, '_id': ObjectId("5826b2313d28909ce9f6ea62"), 'name': 'orange'}, {'price': 50, '_id': ObjectId("5826b2313d28909ce9f6ea63"), 'name': 'banana'}]
>>>

Update

>>> db.fruits.update({'name': 'banana'}, {'$inc': {'price': 20}})
{'nModified': 1, 'ok': 1, 'n': 1}
>>> cur = db.fruits.find({'name': 'banana'})
>>> cur.fetchone()
{'_id': ObjectId("5823dd6d3d28909ce9f6e99c"), 'name': 'banana', 'price': 70}
>>>

Delete

>>> db.fruits.remove({'name': 'banana'})
1
>>> db.fruits.count()
2

Count each collection records

>>> for collection in db.getCollections():
...     print(collection.name, collection.count())
...
fruits 3
>>> db.getCollection('fruits').count()
3
>>>

See also mongo Shell Methods (Collection and Database sections).

Features Not Implemented

Common

  • GridFS

  • ssl

MicroPython

  • datetime.datetime

  • time.struct_time

Download files

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

Source Distribution

nmongo-0.2.2.tar.gz (9.5 kB view details)

Uploaded Source

File details

Details for the file nmongo-0.2.2.tar.gz.

File metadata

  • Download URL: nmongo-0.2.2.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for nmongo-0.2.2.tar.gz
Algorithm Hash digest
SHA256 0480eae2e112ee8fa92794445a0ea9c792764a0833cbcfcc8ad7079b496a3199
MD5 48abe0301677b5d23fa9be77c0ec3b7d
BLAKE2b-256 c1efb25f28b7e2828ebcb08c74c67d3f4ab6e38e4139e90861116f1925276734

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page