pymongo加索引以及查看索引例子
索引 查看 以及 例子 pymongo
2023-09-14 09:06:36 时间
# -*- coding: utf-8 -*-
# @Time : 2018/12/28 10:01 AM
# @Author : cxa
import pymongo
db_configs = {
'type': 'mongo',
'host': '地址',
'port': '端口',
'user': 'spider_data',
'passwd': '密码',
'db_name': 'spider_data'
}
class Mongo():
def __init__(self, db=db_configs["db_name"], username=db_configs["user"],
password=db_configs["passwd"]):
self.client = pymongo.MongoClient(f'mongodb://{db_configs["host"]}:3717')
self.username = username
self.password = password
if self.username and self.password:
self.db1 = self.client[db].authenticate(self.username, self.password)
self.db1 = self.client[db]
def find_data(self):
# 获取状态为0的数据
data = self.db1.test.find({"status": 0})
gen = (item for item in data)
return gen
def add_index(self):
# status_code 0:初始,1:开始下载,2下载完了
self.db1.test.create_index([('name', pymongo.ASCENDING)], unique=True)
def get_index(self,):
indexlist=self.db1.test.list_indexes()
for index in indexlist:
print(index)
if __name__ == '__main__':
m = Mongo()
print(m.get_index())
相关文章
- PostgreSQL索引类型
- MySQL建索引需要的原则
- dirsearch使用方法_查看es某个索引下的所有数据
- ElasticSearch学习(二)——索引、文档简单操作
- oracle 索引的相关介绍(创建、简介、技巧、怎样查看) .
- PostgreSQL 查看数据库,索引,表,表空间大小的示例代码
- 用where导致group by分组字段的索引失效详解数据库
- 深入探究MySQL索引类型及使用方式(mysql索引方式)
- Oracle中查看索引使用方法(oracle中查看索引)
- MySQL索引使用完整的语法指南(mysql索引语法)
- 深入探索Oracle数据库中的索引(oracle如何查看索引)
- 深入浅出Oracle查看索引字段(oracle查看索引字段)
- Oracle查看索引列的方法(oracle查看索引列)
- 查看Oracle索引碎片:实现优化(oracle查看索引碎片)
- MySQL查看所有索引:一次性操作搞定(mysql查看所有索引)
- Oracle 查看索引数据的实用技巧(oracle查看索引数据)
- 如何在MySQL中查看索引?(mysql查看索引)
- Oracle 索引类型:简要概述(oracle索引的种类)
- 情况MySQL 查看索引使用情况:一个指南(mysql查看索引使用)
- MySQL索引查询方法:怎样查询MySQL索引(mysql如何查看索引)
- 优化查询性能:MySQL索引选用技巧(mysql如何选择索引)
- mssql中查看索引大小的方法(mssql 查看索引大小)
- 使用MSSQL查看字段的索引信息(mssql 查看字段索引)
- 优化MySQL数据库应用索引的使用(c mysql 索引)
- MySQL索引从多样性中收获优化(4.mysql索引种类)
- Oracle中查看表索引一步一步操作(oracle中查看表索引)
- 索引Oracle中位图索引发挥其最大威力(Oracle中什么叫位图)
- 使用Redis实现高效队列索引(redis队列索引)
- Oracle数据库中索引的构成及其功能(oracle中索引包括)
- PostgreSQL查看数据库,索引,表,表空间大小的示例代码