def send_to_mongo(industry, table, data): print "send_to_mongo" #msg_dict = eval(msg) global mongo_conn table_name = get_mongo_table(industry, table) table = mongo_conn.dataplatform[table_name] #print msg_dict new_dict = format_record(data) # new_dict["_id"] = get_object_id(data_dict) # TODO #new_dict[TTL_FIELD] = datetime.datetime.utcnow() new_dict[TTL_FIELD] = int(round(time.time())) print new_dict table.save(new_dict) return True
def _query_index(industry, storeID, key, para1): collection = mongo_conn.dataplatform table_name = get_mongo_table(industry, "index") table = collection[table_name] key_name = 'pageID' # TODO # TODO pipeline = [{'$match':{'storeID':storeID, key_name:para1, 'name':key}}, {'$group':{'_id':'$'+key_name,'value':{'$sum':'$value'}}}] json_data = collection.command('aggregate', table_name, pipeline=pipeline) result = json_data['result'] if len(result) != 1: status = "error" value = "-1" else: status = "ok" value = result[0]['value'] content = render_template('query_index.json', status=status, value=value) content = smarty_remove_extra_comma(content) return content