为何 PyMongo 在记录中插入 _id 字段
来源:互联网 发布:淘宝加盟公司靠谱吗 编辑:程序博客网 时间:2024/06/02 04:10
- MongoDB 要求每个文档都必须有 _id
- 如果待插入的文档没有 _id, MongoDB 会自动生成一个,但不会把结果返回个 PyMongo
- 对于需要写操作频繁的应用来说, 在写入之前复制一份插入 _id 代价可能会很高
如果你不想自动生成的 _id, 就需要自己在插入数据前 自己准备好 _id 字段
Why does PyMongo add an _id field to all of my documents?¶
When a document is inserted to MongoDB using insert_one()
, insert_many()
, or bulk_write()
, and that document does not include an _id
field, PyMongo automatically adds one for you, set to an instance of ObjectId
. For example:
Users often discover this behavior when calling insert_many()
with a list of references to a single document raises BulkWriteError
. Several Python idioms lead to this pitfall:
PyMongo adds an _id
field in this manner for a few reasons:
- All MongoDB documents are required to have an
_id
field. - If PyMongo were to insert a document without an
_id
MongoDB would add one itself, but it would not report the value back to PyMongo. - Copying the document to insert before adding the
_id
field would be prohibitively expensive for most high write volume applications.
If you don’t want PyMongo to add an _id
to your documents, insert only documents that already have an _id
field, added by your application.
0 0
- 为何 PyMongo 在记录中插入 _id 字段
- pymongo统计字段是否存在的记录
- 从默认的 _id 字段中,取得时间信息
- 在oracle中插入CLOB字段
- 在Python中使用pymongo操作mongodb
- ]在GridView中插入新记录
- [翻译]在GridView中插入新记录
- 怎么在MySQL中插入大量记录
- 在DNS数据库中插入记录
- 将刚插入的记录的自增Id,插入到另一个字段中
- 在临时表中插入字段的方法
- mongodb通过_id查找记录
- 在存储过程中取得刚刚插入的记录的某个字段,将其输出,由C#接受OUTPUT返回参数
- 在mapred程序中调用pymongo遇上的问题
- 在Python中使用PyMongo操控MongoDB的方法
- 在Select 语句中添加一个记录号的字段
- 在postgresql中获得当前插入记录的id
- 在JAVA中查询刚插入的记录ID
- ROS(10):mac 下树莓派Raspberry Pi 烧录 img
- Your Apple ID account is also attached to other iTunes providers. You will need to create a new user
- Android之自定义属性简单使用-----获取自定义属性
- BZOJ 3131 [Sdoi2013] 淘金
- Xcode常用快捷键
- 为何 PyMongo 在记录中插入 _id 字段
- 第一行代码学习3(10)
- Linux目录标准
- UIWebview交互之自定义传值跳转
- MaterialPropertyDrawer自定义Unity材质Inspector之关键字枚举(KeywordEnum)
- 淘宝tair介绍
- Fiddler实现手机抓包——小白入门
- dmam_pool_create
- [乐意黎转载]AngularJS TODO Application