Commit 685f4117 by 陈森彬

添加mongo类

parent 1bed00a1
Showing with 22 additions and 0 deletions
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import pymongo
from config import get_mongo_conf
from urllib.parse import quote_plus
class MongoOperator:
def __init__(self):
config = get_mongo_conf()
uri = 'mongodb://%s:%s@%s/%s' % (
quote_plus(config['user']), quote_plus(config['password']), config['host'], config['database'])
self.conn = pymongo.MongoClient(uri)
self.db = self.conn[config['database']]
self.collection = self.db["spu"]
def find_goods_data(self,data):
return self.collection.aggregate([{'$match': {"$or":data}}, {"$group": {"_id": "$spu_name", "num_tutorial": {"$sum": 1}}}])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment