MongoDB 是一个基于分布式文件存储的数据库。由 C++ 语言编写。旨在为 WEB 应用提供可扩展的高性能数据存储解决方案。
MongoDB 是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的。
本文给大家介绍MongoDB的插入文档的方法,一起看看吧
1、文档的数据存储格式为BSON,类似于JSON。MongoDB插入数据时会检验数据中是否有“_id”,如果没有会自动生成。
shell操作有insert和save两种方法。当插入一条数据有“_id”值,并且现在集合中已经有相同的值,使用insert插入时插入不进去,使用save时,会更新数据。
> db.student.drop() true > db.student.insert({"_id": 1, "name":"zhangsan", "age": 28}) WriteResult({ "nInserted" : 1 }) > db.student.find() { "_id" : 1, "name" : "zhangsan", "age" : 28 } > db.student.insert({"_id": 1, "name":"zhangsan", "age": 27}) WriteResult({ "nInserted" : 0, "writeError" : { "code" : 11000, "errmsg" : "E11000 duplicate key error collection: zyhdb.student index: _id_ dup key: { : 1.0 }" } }) > db.student.find() { "_id" : 1, "name" : "zhangsan", "age" : 28 } > db.student.save({"_id": 1, "name":"zhangsan", "age": 27}) WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 }) > db.student.find() { "_id" : 1, "name" : "zhangsan", "age" : 27 }
2、批量插入,网上的文档都说不能MongoDB不支持批量插入,现在试过可以,应该是目前的版本支持批量插入了。
> db.student.insert([{"_id": 2, "name": "lisi"},{"_id": 3, "name": "wangwu"}, {"_id": 4, "name": "zhaoliu", "age": 28}]) BulkWriteResult({ "writeErrors" : [ ], "writeConcernErrors" : [ ], "nInserted" : 3, "nUpserted" : 0, "nMatched" : 0, "nModified" : 0, "nRemoved" : 0, "upserted" : [ ] }) > db.student.find() { "_id" : 1, "name" : "zhangsan", "age" : 27 } { "_id" : , "name" : "lisi" } { "_id" : , "name" : "wangwu" } { "_id" : 4, "name" : "zhaoliu", "age" : 28 }
3、循环插入:
> for(var i=; i<; i++){db.fortest.insert({num: i})} WriteResult({ "nInserted" : }) > db.fortest.find() { "_id" : ObjectId("eceadaeabab"), "num" : 0} { "_id" : ObjectId("eceadaeabab"), "num" : 1} { "_id" : ObjectId("eceadaeabab"), "num" : 2} { "_id" : ObjectId("eceadaeabab"), "num" : 3} { "_id" : ObjectId("eceadaeabab"), "num" : 4} { "_id" : ObjectId("eceadaeababa"), "num" : 5} { "_id" : ObjectId("eceadaeababb"), "num" : 6} { "_id" : ObjectId("eceadaeababc"), "num" : 7} { "_id" : ObjectId("eceadaeababd"), "num" : 8} { "_id" : ObjectId("eceadaeababe"), "num" : 9}
以上所述是小编给大家介绍的MongoDB快速入门笔记(三)之MongoDB插入文档操作的相关知识,希望对大家有所帮助,更多精彩内容,敬请关注网站!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线
暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。
艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。
《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。
更新日志
- 大自然音乐系列《听见向日葵的微笑》[WAV/CUE/分轨][538.5MB]
- 魔兽世界地心之战戒律牧用什么饰品 地心之战戒律牧饰品推荐
- 魔兽世界地心之战戒律牧用什么合剂食物 地心之战戒律牧合剂食物推荐
- 仙境传说新启航职业排行榜大全 仙境传说最强职业是哪个
- 群星《网络新歌曲速报》3CD[DTS-WAV分轨]
- 群星《男人必听》一张男人开车时必听的绝世好歌[WAV]
- 群星《再见新歌》2CD【DTS-WAV分轨】
- 黎瑞恩.1992-雨季不再来【宝丽金】【WAV+CUE】
- 曹雅雯.2018-小说【美乐蒂】【FLAC分轨】
- 温拿乐队.2007-温拿33好时光演唱会2CD(2024环球红馆40复刻系列)【环球】【WAV+CUE】
- 魔兽世界地心之战戒律牧用什么附魔宝石 地心之战戒律牧附魔宝石推荐
- 仙境传说新启航公测兑换码汇总 仙境传说最新兑换码礼包大全
- 魔兽世界地心之战神牧用什么饰品 地心之战神牧饰品推荐
- 群星《聆听·极致女声》2CD[DTS-WAV]
- 群星《五大最美女中音》2CD[DTS-WAV]