def attr_gen(self): a_1 = 0 a_2 = 1 share_common = -(random.randint(1, 1000)) share_0 = -(share_common) share_1 = share_0 + 1 x=objectid()
def delete(): try: id = request.args.get('_id') client = MongoClient('localhost', 27017) db = client.bit collection = db.member collection.delete_one({'_id':objectid(id)}) return redirect('http://203.236.209.139:9090/hi.do') except Exception as e: return redirect('http://203.236.209.139:9090/.do') finally: client.close()
def push(): try: uid = request.args.get('_id') Isin = request.args.get('Isin') client = MongoClient('localhost', 27017) db = client.bit collection = db.member _id = collection.update_one({'_id':objectid(uid)},{'$push':{'Isin':Isin}}).updated_id return redirect('/MemberInfo.do?_id='+_id) except Exception as e: return redirect('http://203.236.209.139:9090/.do') finally: client.close()
def info(): try: _id = request.args.get('_id') client = MongoClient('localhost', 27017) db = client.bit collection = db.member result = collection.find_one({'_id':objectid(_id)}) return render_template("Member.html" ,data=result) except Exception as e: return redirect('http://203.236.209.139:9090/hi.do') finally: client.close()
def set(): try: uid = request.form['_id'] id = request.form['id'] pwd = request.form['pwd'] name = request.form['name'] age = request.form['age'] tel = request.form['tel'] client = MongoClient('localhost', 27017) db = client.bit collection = db.member m = {'id':id,'pwd':pwd,'name':name,'age':age,'tel':tel} _id = collection.update_one({{'_id':objectid(uid)},{'$set':m}}).updated_id return redirect('/MemberInfo.do?_id='+_id) except Exception as e: return redirect('http://203.236.209.139:9090/.do') finally: client.close()
def recommend(): results = collection.aggregate([{ "$match" : { "system_name" :"PMS"}},{ "$group" : { "_id" : { "create_uid" : "$create_uid" },"id" : { "$max" : "$_id" } } }]) for i in results: print(bson.objectid(i[0]))
def search_collections(db, collections): result = db[collections].find_one({'name': 'Mike'}) result = db[collections].find_one( {'_id': objectid('593278c115c2602667ec6bae')}) #大于查询语句 result = db[collections].find({'age': {'$gt': 20}})