標籤:search command
登陸
mongo 192.168.0.134:27017
查看庫
show dbs
建立庫
use test
db.createCollections("command")
查看庫中的表
show collections;
插入語句
db.command.insert({name:"ssh",decriptions:"this is login remote host command"})
db.command.insert({name:"ifconfig",decriptions:"It can search for IP"})
db.user.insert({name:"zhangsan",age:"20"})
db.user.insert({name:"lisi",age:"21"})
db.user.insert({name:"zhaowu",age:"30"})
db.user.insert({name:"wangliu",age:"55"})
查詢語句
db.command.find()
條件查詢
db.command.find({name:"ifconfig"}) 查詢name=/ifconfig/的json
db.command.find().limit(2) 只查看前兩行
db.user.find(‘this.age>"30"‘)
db.user.find().sort({age:1}) 升序查詢
db.user.find().sort({age:-1})降序查詢
刪除庫
use test
db.dropDatabase()
刪除表
db.command.drop()
刪除一個欄位
db.user.remove({name="zhangsan"})
條件刪除
db.user.remove({‘this.age>"30"‘})
統計行數
db.user.count()
更新語句
db.user.update({name:"lisi"},{$set:{age:"21"}})
本文出自 “常用文檔” 部落格,請務必保留此出處http://yujianglei.blog.51cto.com/7215578/1603861
mongodb 基本類sql命令基礎學習