mongodb基本语句操作

mongo数据库的基本操作

1、{ “authors.name” : { $type : 2} }

2、{ ‘authors.org’: { $type : 4} }

查询作者字段下面的,org字段里面是否有list对象,本来里面应该全是对象类型的。
https://docs.mongodb.com/manual/reference/operator/query/type/

总览
https://docs.mongodb.com/manual/reference/glossary/#std-term-BSON

3、{ ‘venue.sid’: { $exists: false } }

查询不存在这个字段的记录
https://docs.mongodb.com/manual/reference/operator/query/exists/

4、{’_id’:ObjectId(‘5feee51891e0113b2659fd0e’)}

5、** 数据库连接的类**


#-*- 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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值