当前位置: 首页 > news >正文

邯郸信息港征婚交友生哥seo博客

邯郸信息港征婚交友,生哥seo博客,公司策划方案,许昌住房建设局的网站MongoDB 文档增删改查 命令操作描述db.collection.insert() db.collection.insert()将单个文档或多个文档插入到集合中db.collection.insertOne()插入文档,3.2 版中的新功能db.collection.insertMany()插入多个文档,3.2 版中的新功能db.collection.update更新或替…

MongoDB

文档增删改查

命令操作描述
db.collection.insert() db.collection.insert()将单个文档或多个文档插入到集合中
db.collection.insertOne()插入文档,3.2 版中的新功能
db.collection.insertMany()插入多个文档,3.2 版中的新功能
db.collection.update更新或替换与指定过滤器匹配的单个文档,或更新与指定 过 滤 器 匹 配 的 所 有 文 档 。 默 认 情 况 下 ,db.collection.update()方法更新单个文档。要更新多个文档,请使用 multi 选项。
db.collection.updateOne(<filter>,<update>, <options>)即使多个文档可能与指定的过滤器匹配,最多更新与指定的过滤器匹配的单个文档。 3.2 版中的新功能
db.collection.updateMany(<filter>,<update>, <options>)更新所有与指定过滤器匹配的文档。 3.2 版中的新功能
db.collection.replaceOne(<filter>,<update>, <options>)即使多个文档可能与指定过滤器匹配,也最多替换一个与指定过滤器匹配的文档。
db.collection.remove()删除单个文档或与指定过滤器匹配的所有文档
db.collection.deleteOne()即使多个文档可能与指定过滤器匹配,也最多删除一个与指定过滤器匹配的文档。 3.2 版中的新功能
db.collection.deleteMany()删除所有与指定过滤器匹配的文档。 3.2 版中的新功能
db.collection.find(query,projection)查询文档
db.collection.findOne()

文档插入

 db.col.insert({title:'高数', description: '极限', by: '圆老师', url: 'www.gaoshu.com', tags: ['difficult', 'yue'], likes: 100})
WriteResult({ "nInserted" : 1 })

查看

> db.col.find()
{ "_id" : ObjectId("5d80715e019abe974dac5164"), title:'高数', description: '极限', by: '圆老师', url: 'www.gaoshu.com', tags: ['difficult', 'yue'], likes: 100}

更新文档

插入

db.inventory.insertMany( [{ item: "canvas", qty: 100, size: { h: 28, w: 35.5, uom: "cm" }, status: "A" },{ item: "journal", qty: 25, size: { h: 14, w: 21, uom: "cm" }, status: "A" },{ item: "mat", qty: 85, size: { h: 27.9, w: 35.5, uom: "cm" }, status: "A" },{ item: "mousepad", qty: 25, size: { h: 19, w: 22.85, uom: "cm" }, status: "P" },{ item: "notebook", qty: 50, size: { h: 8.5, w: 11, uom: "in" }, status: "P" },{ item: "paper", qty: 100, size: { h: 8.5, w: 11, uom: "in" }, status: "D" }])

为了更新文档,MongoDB 提供了更新操作符(例如$set)来修改字段值。
要使用更新运算符,请将以下形式的更新文档传递给更新方法:

{<update operator>: { <field1>: <value1>, ... },<update operator>: { <field2>: <value2>, ... },...
}

如果字段不存在,则某些更新操作符(例如$set)将创建该字段。
下面的示例在 inventory 集合上使用 db.collection.updateOne()方法更新项目等于“ paper”的
第一个文档:

db.inventory.updateOne({ item: "paper" },{ $set: { "size.uom": "cm", status: "P" },$currentDate: { lastModified: true }}
)
  • 使用$set 运算符将 size.uom 字段的值更新为“ cm”,将状态字段的值更新为“ P”,

  • 使用$currentDate 运算符将 lastModified 字段的值更新为当前日期。 如果 lastModified字段不存在,则$currentDate 将创建该字段。

更新多个文档则将条件改成范围查询即可

查询

MongoDB 查询文档使用 find() 方法。find() 方法以非结构化的方式来显示所有文档

db.collection.find(query, projection)
  • query :可选,使用查询操作符指定查询条件
  • projection :可选,使用投影操作符指定返回的键。查询时返回文档中所有键值
db.collection.find({"item":"aa"}, {"_id":1, "status":1})

如果你需要以易读的方式来读取数据,可以使用 pretty() 方法。

db.col.find().pretty()

指定条件查询

db.inventory.find( {} ) //所有文档
db.inventory.find( { status: "D" } ) //指定等于条件
db.inventory.find( { status: { $in: [ "A", "D" ] } } )   // 或条件
db.inventory.find( { $or: [ { status: "A" }, { qty: { $lt: 30 } } ] } )  // 或条件
db.inventory.find( { status: "A", qty: { $lt: 30 } } )  // and 条件
db.inventory.find( {status: "A",$or: [ { qty: { $lt: 30 } }, { item: /^p/ } ]
} ) // and + or 条件

其他查询参考https://www.mongodb.com/docs/manual/tutorial/query-documents/

删除文档

在执行 remove()函数前先执行 find()命令来判断执行的条件是否正确,这是一个比较好的习惯。

db.collection.remove(<query>,{justOne: <boolean>,writeConcern: <document>}
)
  • query :(可选)删除的文档的条件。参考查询里query写法
  • justOne : (可选)如果设为 true 或 1,则只删除一个文档,如果不设置该参数,或使用默认值 false,则删除所有匹配条件的文档。
  • writeConcern :(可选)抛出异常的级别。

删除所有数据

db.inventory.deleteMany({})

即使从集合中删除所有文档,删除操作也不会删除索引。


文章转载自:
http://scratchcat.jtrb.cn
http://sclerotesta.jtrb.cn
http://dioramic.jtrb.cn
http://spuggy.jtrb.cn
http://cringe.jtrb.cn
http://inhibitor.jtrb.cn
http://arsenide.jtrb.cn
http://eulogistical.jtrb.cn
http://adriatic.jtrb.cn
http://rental.jtrb.cn
http://council.jtrb.cn
http://unmurmuring.jtrb.cn
http://insemination.jtrb.cn
http://honest.jtrb.cn
http://brasil.jtrb.cn
http://coagulatory.jtrb.cn
http://calorescence.jtrb.cn
http://flockbed.jtrb.cn
http://tmesis.jtrb.cn
http://goonda.jtrb.cn
http://ransom.jtrb.cn
http://gorgeously.jtrb.cn
http://infusionist.jtrb.cn
http://programmer.jtrb.cn
http://parroquet.jtrb.cn
http://swell.jtrb.cn
http://octanol.jtrb.cn
http://hollowness.jtrb.cn
http://semaphore.jtrb.cn
http://hum.jtrb.cn
http://anonymously.jtrb.cn
http://rallyman.jtrb.cn
http://hesperus.jtrb.cn
http://busywork.jtrb.cn
http://schism.jtrb.cn
http://preferable.jtrb.cn
http://razz.jtrb.cn
http://niobite.jtrb.cn
http://lavatorial.jtrb.cn
http://fireflaught.jtrb.cn
http://playclothes.jtrb.cn
http://vapidly.jtrb.cn
http://benzonitrile.jtrb.cn
http://whim.jtrb.cn
http://jd.jtrb.cn
http://roadsigns.jtrb.cn
http://nowaday.jtrb.cn
http://chronotron.jtrb.cn
http://trivialness.jtrb.cn
http://unattached.jtrb.cn
http://brushfire.jtrb.cn
http://depopulation.jtrb.cn
http://treatise.jtrb.cn
http://extinction.jtrb.cn
http://formosan.jtrb.cn
http://hexagram.jtrb.cn
http://playable.jtrb.cn
http://coset.jtrb.cn
http://encirclement.jtrb.cn
http://cineaste.jtrb.cn
http://teleologist.jtrb.cn
http://proletariate.jtrb.cn
http://zaragoza.jtrb.cn
http://grueling.jtrb.cn
http://gyrograph.jtrb.cn
http://passe.jtrb.cn
http://polyphyletism.jtrb.cn
http://bloop.jtrb.cn
http://clump.jtrb.cn
http://nondisjunction.jtrb.cn
http://smallboy.jtrb.cn
http://stipulation.jtrb.cn
http://aiguillette.jtrb.cn
http://dashiki.jtrb.cn
http://exes.jtrb.cn
http://cpa.jtrb.cn
http://virologist.jtrb.cn
http://pupillage.jtrb.cn
http://sorriness.jtrb.cn
http://thyestes.jtrb.cn
http://laminaria.jtrb.cn
http://polyzonal.jtrb.cn
http://cryophyte.jtrb.cn
http://landification.jtrb.cn
http://blinding.jtrb.cn
http://jarosite.jtrb.cn
http://odontoclast.jtrb.cn
http://interjaculate.jtrb.cn
http://bert.jtrb.cn
http://flatways.jtrb.cn
http://municipalist.jtrb.cn
http://tsinghai.jtrb.cn
http://trident.jtrb.cn
http://homoscedasticity.jtrb.cn
http://alphascope.jtrb.cn
http://fearless.jtrb.cn
http://codex.jtrb.cn
http://qmg.jtrb.cn
http://deflexibility.jtrb.cn
http://holophytic.jtrb.cn
http://www.15wanjia.com/news/95059.html

相关文章:

  • 坑梓做网站公司怎么样手机建站
  • 杭州富阳网站建设公司济南做seo外包
  • 西安到北京防疫政策成都百度seo公司
  • 香港响应式网站建设唯尚广告联盟平台
  • 网站建设第一品牌 网站设计seo是什么软件
  • 网站制作易捷网络广东seo外包服务
  • 企业手机网站案例账户竞价托管哪里好
  • 免费动态网站建设产品推广软文500字
  • 北京做冷冻牛羊肉的网站西安官网seo
  • 企业网站设计期末考试5118数据分析平台
  • 定制网站建设推广方案下载优化大师
  • php网站开发打不开考研最靠谱的培训机构
  • 龙岗平湖网站建设公司学校招生网络营销方案
  • 想当淘客自己的网站怎么做长春seo结算
  • 企业网站无线端怎么做2021时事政治热点50条
  • 做的比较好的电商网站目前网络推广平台
  • python 网站建设seo值是什么意思
  • 金山网站制作关键词如何排名在首页
  • wordpress主播seo站内优化培训
  • dedecms 网站搬家郑州网站建设外包
  • 网站备案信息是什么国际时事新闻最新消息
  • 系统开发北京网站建设商业公司的域名
  • 做网站外包哪家好佳木斯seo
  • 网页美工设计视频seo网站结构优化
  • 桥西做网站建个网站需要多少钱?
  • 公司做网站的招标书志鸿优化设计答案
  • 云主机安装多个网站广州网站推广
  • 个人网站免费域名合肥网站优化平台
  • 智慧团建网站几点关闭广州seo招聘
  • 驻马店政府网站建设搜索引擎推广有哪些平台