1

我正在尝试在 MongoDB 中插入一个使用 pymongo 进行文档验证的文档。它有一个类型验证器来检查数据类型。

db.createCollection( "final",
 { validator: { $and:
     [
         { name: { $type: "string" } },
         { number: { **$type: "int"**} }
     ]
 }
} )

当我使用 mongo shell 插入文档时,我可以使用NumberInt()在整数字段中插入数据。

db.final.insert({ name: "abc", number: **NumberInt(4465)**})

如何使用 pymongo 插入带有整数字段的文档?

4

0 回答 0