赵走x博客
网站访问量:151491
首页
书籍
软件
工具
古诗词
搜索
登录
2、在MongoDB开启验证的情况下,新建一个数据库 dbName
mac 安装mongodb
mongodb同一个document中两个字段比较查询
mongoengine 关系处理
mongoengine查询
ubuntu安装mongodb(不使用docker)
Centos安装mongodb(不使用docker)
MongoDB唯一索引(Unique) 空值问题
1、mongoengine.errors.InvalidQueryError: Cannot perform join in mongoDB
1、sanic中对motor的操作封装
1、mongodb设置密码后无效,还是可以外网无密码访问
1、sanic中对motor的操作封装
资源编号:76469
mongodb相关问题
数据库
热度:105
持续更新中
# 前言 习惯了Flask中[mongoengine](http://docs.mongoengine.org/ "mongoengine") 的各种便利操作,但在[sanic_motor](https://github.com/lixxu/sanic-motor")中却还要写很多原生查询语句,一点都不ORM。 # 基类 MarkModel: ``` from datetime import datetime from bson import ObjectId from sanic_motor import BaseModel class MarkModel(BaseModel): _index__ = None def to_json(self): res = {} for key in self.__unique_fields__: # print("key-type", key, type(key)) value = self[key] if isinstance(value, datetime): res[key] = value.strftime('%Y-%m-%d %H:%M') elif isinstance(value, ObjectId): res[key] = str(value) else: res[key] = value return res async def save(self): params = {} for key in self.__unique_fields__: params[key] = self[key] if self.id: await self.update_one({self._index__: self[self._index__]}, {"$set": params}, upsert=True) else: await self.insert_one(params) ``` # 应用 UserModel ``` class Info(MarkModel): __coll__ = 'reward' _index__ = 'user_id' __unique_fields__ = ['user_id', "create_time", "name"] ``` ### 1、新建 ``` info=Info() info.user_id=1 infor.create_time=datetime.datetime.now() infor.name=mark infor.save() ```