Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: UTF-8 -*-
- import pymongo
- def get_collection():
- # 连接服务器
- client = pymongo.MongoClient('127.0.0.1', 27017)
- # 连接数据库
- db = client.my_users
- # 获取 collection
- user_collection = db.user_collection
- return user_collection
- class User:
- def __init__(self, username, password):
- self.username = username
- self.password = password
- def save(self):
- user_dict = {'username': self.username, 'password': self.password}
- rec_id = get_collection().insert(user_dict)
- print(rec_id)
- @staticmethod
- def query_users():
- return get_collection().find()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement