How to operate CouchDB in python and couchdb in python

Source: Internet
Author: User
Tags couchdb

How to operate CouchDB in python and couchdb in python

This article briefly describes how to operate CouchDB in python and shares it with you for your reference. The specific method is as follows:

1. Install the python couchDb Library:

Https://pypi.python.org/pypi/CouchDB/0.10

2. Connect to the server

>>> import couchdb>>> couch = couchdb.Server('http://example.com:5984/')

3. Create a database

>>> Db = couch. create ('test') # create a database> db = couch ['mydb'] # use an existing database

4. Create a document and insert it to the database:

>>> doc = {'foo': 'bar'}>>> db.save(doc)('e0658cab843b59e63c8779a9a5000b01', '1-4c6114c65e295552ab1019e2b046b10e')>>> doc{'_rev': '1-4c6114c65e295552ab1019e2b046b10e', 'foo': 'bar', '_id': 'e0658cab843b59e63c8779a9a5000b01'}

The save () method returns the '_ id',' _ rev' fields.

5. query the database by id

>>> db['e0658cab843b59e63c8779a9a5000b01']<Document 'e0658cab843b59e63c8779a9a5000b01'@'1-4c6114c65e295552ab1019e2b046b10e' {'foo': 'bar'}>

6. Update the document:

>>> data = db["5fecc0d7fe5acac6b46359b5eec4f3ff"]  >>> data['billSeconds'] = 191>>> db.save(data)(u'5fecc0d7fe5acac6b46359b5eec4f3ff', u'3-6b8a6bb9f2428c510dcacdd5c918d632')

7. traverse the database

>>> for id in db:...   print id...'e0658cab843b59e63c8779a9a5000b01'

8. delete documents and clear Databases

>>> db.delete(doc)>>> couch.delete('test')

I hope this article will help you with Python programming.


How does python perform random operations on the keyboard;

Run the Python code to simulate the keyboard operation Ctrl + V. Other keys are also supported. You can call the win32 function using the pywin module to import win32api import win32con win32api. keybd_event (17,

Repeated errors occur when Python calls CouchDB insert.

You can use pydoc couchdb to query its documentation
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.