3. Insert # insert an array and general character seek
Db. wbinfo. insert ({"city": cityname, "jiaojing": [jiaojing], "lukuang": "lukuang ,"})
4. Insert arrays by push and pop to delete array elements
Db. wbinfo. update ({"city": "LU 'an city" },{ '$ push': {"jiaojing": "two", "lukuang": "lk "}})
Db. wbinfo. update ({"city": "LU 'an city" },{ '$ pop': {"jiaojing": "two", "lukuang": "lk "}})
5. Regular expression query
Res = db. devices. find ({'$ and': [{'stats. devcaps ': {' $ exists': True }}, {'stats. fwver ': {' $ regex ':'. * N91 | N92. * '}]}) # stats. the fwver field contains the character 'n91 'or 'n92'
6. dictionary
If devcap. has_key ('dev') and devcap. has_key ('Cap '):
7.
Python code used to query data by _ id in mongodb
ObjectId pymongo python
If the Python version is earlier than 2.2, use the following statement to import ObjectId.
From pymongo. objectid import ObjectId
If the version number of pymongo is greater than 2.2, use the following statement.
From bson. objectid import ObjectId
The query code is as follows:
Collection. find_one ({'_ id': ObjectId ('50f0d76109f4ec148890ef1e ')})
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.