赞
踩
Show dbs
db
use 数据库名
db.createCollection(“集合名”)
show collections
db.集合名.drop()
db.集合名称.insert(document) db.student.insert({name:'zhangsan',gender:1}) db.student.insert({_id:"20170101",name:'gj',gender:1})
db.集合名称.update(<query> ,<update>,{multi: <boolean>}) db.student.update({name:'hr'},{name:'mnc'}) # 更新一条 db.student.update({name:'hr'},{$set:{name:'hys'}}) # 更新一条 db.student.update({},{$set:{gender:0}},{multi:true}) 更新全部
db.集合名称.find()
db.goodsbaseinf.insert( {name:"<c语言>", bookprice:33.2, adddate:2017-10-1, allow:true, baseinf:{ISBN:183838388,press:"清华大学出版社"}, tags:["good","book","it","Program"] })
db.testinf.insert( [ { item: "小学生教材",name:"《小学一年级语文(上册)》",price:12 }, { item: "初中生教材",name:"《初中一年级语文(上册)》",price:15}, { item: "高中生教材",name:"《高中一年级语文(上册)》",price:20}, { item: "外语教材",name:"《英语全解\nABC(五年级上)》",price:30} ] )
document=({name:"《C语言编程》",price:32}) db.testinf.insert(document)
db.testinf.insert( [ {_id:10,item:"小学生教材",name:"《小学二年级语文(上册)》",price:10}, {_id:12,item:"小学生教材",name:"《小学四年级语文(上册)》",price:13}, {_id:11,item:"小学生教材",name:"《小学三年级语文(上册)》",price:12} ], {ordered:true} ) db.testinf.find().pretty()
命令行模式下,格式化find()的返回结果,pretty()
使用 db.demo.find() 返回数据,每一条占一整行,不便于阅读,寻找能格式化输出结果的方法,
其实MongoDB本身提供了该方法,在find()方法后直接追加pretty()方法即可,如下:
(含insert 命令出错返回对象显示)。
db.testinf.insert( { _id:1,item:"大学生教材",name:"《大学一年级语文(上册)》",price:50 }, { writeConcern: { w:"majority",wtimeout:5000 } } )
MongoDB 3.2 开始出现了两种新的文档插入命令: (1) db.collection.insertOne() (2) db.collection.insertMany()
db.testinf.insertOne( { name:"《c语言编程(V2)》",price:32 } )
db.testinf.insertMany( [ {name:"《B语言编程(V2)》",price:32}, {name:"《A语言编程(V2)》",price:40}, {name:"《D语言编程(v2)》",price:50} ] )
db.testinf.find()
db.testinf.find( { name:"《C语言编程》" } )
不想显示_id 及值,并指定显示值查询
db.testinf.find( { name:"《C语言编程》" }, { name:1,price:1,_id:0 } )
db.testinf.find ( { "baseinf.press":"清华大学出版社" } )
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。