| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- # coding=utf-8
- '''
- Created on 2016年4月5日
- 使用mongodb对数组的条件查询快速得到property
- @author: ChenHao
- '''
- from pymongo.mongo_client import MongoClient
- from util_common import Constant
- '''
- 用一开始总结出来的60个初始化
- 今后不需要用这段初始化的代码了
- @date 2016年4月5日14:22:28
- '''
- # file_path = "../spider_download/Other/labelAndName.csv"
- # fin = open(file_path, "r")
- # lines = fin.readlines()
- # fin.close()
- #
- # properties_list = list()
- # for index, line in enumerate(lines):
- # temp_list = line.split(",")
- # d = dict()
- # d["id"] = temp_list[0]
- # d["labelCn"] = temp_list[1]
- # d["labelEn"] = temp_list[2]
- # properties_list.append(d)
- #
- # cli = MongoClient(Constant.MONGODB_URL)
- # db = cli.spider
- # db.property.insert_many(properties_list)
- # cli.close()
- '''
- 1、得到所有的
- '''
- cli = MongoClient(Constant.MONGODB_URL)
- db = cli.spider
- # rs = db.component_original.find().distinct("properties.lable")
- # for r in rs:
- # print (r)
- # print (len(rs))
- rs = db.property.find()
- print (rs.count())
- for r in rs:
- print (type(r["id"]))
- r["id"] = int(r["id"])
- print (type(r["id"]))
- db.property.save(r)
- cli.close()
|