【发布时间】:2020-12-05 00:34:02
【问题描述】:
我有一个具有给定架构的集合:
{
"name" : "check3",
"type" : "collection",
"options" : {
"validator" : {
"$jsonSchema" : {
"bsonType" : "object",
"properties" : {
"TIMEDESC" : {
"bsonType" : "timestamp"
},
.............
...........
当我尝试插入文档时出现验证错误:
import datetime
from pymongo import MongoClient
db = MongoClient()['poc']
data = {
'TIMEDESC': datetime.datetime.now()
}
mycol = db['check3']
x = mycol.insert_one(data)
pymongo.errors.WriteError:文档验证失败,完全错误: {'index': 0, 'code': 121, 'errmsg': '文档验证失败'}
【问题讨论】: