设为首页 加入收藏

TOP

MongoDB数据库(二):增删查改(二)
2019-09-17 18:52:31 】 浏览:204
Tags:MongoDB 数据库 增删 查改
, "userid" : "fa" } > db.userinfo.update({country:"china"},{set:{country:"zhongguo"}}) # 把country等于china的整条数据替换掉,只替换一条数据 WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 }) > db.userinfo.find() # 第一条数据被替换,只有_id字段没有改变 { "_id" : ObjectId("5c94f37d25000fc9936a9759"), "set" : { "country" : "zhongguo" } } { "_id" : ObjectId("5c94f38425000fc9936a975a"), "country" : "china", "province" : "sh", "userid" : "b" } { "_id" : ObjectId("5c94f38625000fc9936a975b"), "country" : "china", "province" : "sh", "userid" : "c" } { "_id" : ObjectId("5c94f39325000fc9936a975c"), "country" : "china", "province" : "bj", "userid" : "da" } { "_id" : ObjectId("5c94f39925000fc9936a975d"), "country" : "china", "province" : "bj", "userid" : "fa" } > db.userinfo.update({country:"china"},{$set:{country:"zhongguo"}}) # 把country等于china的字段更新为country等于zhongguo,只更新一条数据 WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 }) > db.userinfo.find() { "_id" : ObjectId("5c94f37d25000fc9936a9759"), "set" : { "country" : "zhongguo" } } { "_id" : ObjectId("5c94f38425000fc9936a975a"), "country" : "zhongguo", "province" : "sh", "userid" : "b" } { "_id" : ObjectId("5c94f38625000fc9936a975b"), "country" : "china", "province" : "sh", "userid" : "c" } { "_id" : ObjectId("5c94f39325000fc9936a975c"), "country" : "china", "province" : "bj", "userid" : "da" } { "_id" : ObjectId("5c94f39925000fc9936a975d"), "country" : "china", "province" : "bj", "userid" : "fa" } > db.userinfo.update({country:"china"},{$set:{country:"zhongguo"}},{multi:true}) # 把country等于china的字段更新为country等于zhongguo,multi的值为true,所以更新所有符合条件的数据 WriteResult({ "nMatched" : 3, "nUpserted" : 0, "nModified" : 3 }) > db.userinfo.find() { "_id" : ObjectId("5c94f37d25000fc9936a9759"), "set" : { "country" : "zhongguo" } } { "_id" : ObjectId("5c94f38425000fc9936a975a"), "country" : "zhongguo", "province" : "sh", "userid" : "b" } { "_id" : ObjectId("5c94f38625000fc9936a975b"), "country" : "zhongguo", "province" : "sh", "userid" : "c" } { "_id" : ObjectId("5c94f39325000fc9936a975c"), "country
首页 上一页 1 2 3 4 5 6 7 下一页 尾页 2/10/10
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇oracle 子查询 where having from.. 下一篇MIT-6.824 Lab 3: Fault-tolerant..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目