Basic operation of mongo database
1、{ “authors.name” : { $type : 2} }
2、{ ‘authors.org’: { $type : 4} }
Query whether there are list objects in the org field under the author field, which should be all object types.
https://docs.mongodb.com/manual/reference/operator/query/type/
Overview
https://docs.mongodb.com/manual/reference/glossary/#std-term-BSON
3、{ ‘venue.sid’: { $exists: false } }
Query records that do not exist in this field
https://docs.mongodb.com/manual/reference/operator/query/exists/
4、{’_id’:ObjectId(‘5feee51891e0113b2659fd0e’)}
5. **Class of database connection**
#-*- encoding: utf-8 -*-
from calendar import day_name
import pymongo
from config import mongodb_ip,mongodb_port
"""
使用方法如下所示:
table_database=mongodb_connect.MongoDBUtil('web')
# 传入你要使用的数据库名称
table_uesrEventLog=table_database.create_database('user_event_log')
# 传入你要使用的数据表名称
"""
class MongoDBUtil:
"""
MongoDB工具类
"""
def __init__(self,db_name=None):
"""构造函数"""
self.mongo_client = pymongo.MongoClient(host=mongodb_ip, port=mongodb_port)
self.mongo_auth_db = self.mongo_client.aminer
self.mongo_auth_db.authenticate(name="aminer_platform_reader", password="Reader@123", mechanism="SCRAM-SHA-1")
self.mongo_db_web = self.mongo_client[db_name]
def __del__(self):
"""析构函数"""
# print("__del__")
self.mongo_client.close()
def create_database(self, table_name):
self.table_uesrEventLog = self.mongo_db_web[table_name]
"""创建数据库"""
return self.table_uesrEventLog