设为首页 加入收藏

TOP

Mongodb操作详解(一)(一)
2014-11-24 08:24:04 来源: 作者: 【 】 浏览:9
Tags:Mongodb 操作 详解

Mongodb操作详解(一)
C:\Users\Administrator>F:
F:\>cd Mongodb206
F:\Mongodb206>cd bin
F:\Mongodb206\bin>mongo.exe
MongoDB shell version: 2.0.6
connecting to: test
> show dbs; //显示所有的 数据库,相当于 mysql的show databases;
local (empty) //只有一个local数据库(无表)
> use local //选择local数据库
switched to db local www.2cto.com
> show tables; //show tables
> //无表显示
> post = {"title":"My Blog Post",
... "content":"Here's my blog post.",
... "created":new Date()}
//post字典变量,是java script语句,如new Date()
//其实shell运行环境支持java script语言,
{
"title" : "My Blog Post",
"content" : "Here's my blog post.",
"created" : ISODate("2012-08-11T11:38:08.698Z")
}
> db.blog.insert(post)
//把post数据输入local数据库中blog(数据库中
//不存在就自动建立)集合(即表)中
> db.blog.find() //将blog中数据全部找出,相当与select * from blog;
{ "_id" : ObjectId("502644352d31a25926fc6e85"), "title" : "My Blog Post", "conte
nt" : "Here's my blog post.", "created" : ISODate("2012-08-11T11:38:08.698Z") }
>db.blog.findOne() //只查找集合(表)中一个文档(行)数据
{ "_id" : ObjectId("502644352d31a25926fc6e85"), "title" : "My Blog Post", "conte
nt" : "Here's my blog post.", "created" : ISODate("2012-08-11T11:38:08.698Z") }
更新 update
> post.comments=[] //给之前的那个post字典变量添加一个comments键值
[ ]
> db.blog.update({title:"My Blog Post"},post)
//update()至少接受两个参数,第一个为限制条件,第二个为更改内容
//执行这个后,原文档(行)添加一个字段comments值为空。
> db.blog.find()
{ "_id" : ObjectId("502644352d31a25926fc6e85"), "title" : "My Blog Post", "conte
nt" : "Here's my blog post.", "created" : ISODate("2012-08-11T11:38:08.698Z"), "
comments" : [ ] }
> www.2cto.com
删除 remove delete
> db.blog.remove({title:"My Blog Post"})
//删除title为这个的一文档(行)数据
帮助 help
> help //查询mongo的java script shell的帮助
db.help() help on db methods
db.mycoll.help() help on collection methods
rs.help() help on replica set methods
help admin administrative help
help connect connecting to a db help
help keys key shortcuts
help misc misc things to know
help mr mapreduce
show dbs show database names
show collections show collections in current database
show users show users in current database
show profile show most recent system.profile entries wit
h time >= 1ms
show logs show the accessible logger names
show log [name] prints out the last segment of log in memor
y, 'global' is default
use set current database
db.foo.find() list objects in collection foo
db.foo.find( { a : 1 } ) list objects in foo where a == 1
it result of the last line eva luated; use to f
urther iterate
DBQuery.shellBatchSize = x set default number of items to display on s
hell
exit quit the mongo shell
> db.help() //查询数据库级帮助
DB methods:
db.addUser(username, password[, readOnly=false])
db.auth(username, password) www.2cto.com
db.cloneDatabase(fromhost)
db.commandHelp(name) returns the help for the command
db.copyDatabase(fromdb, todb, fromhost)
db.createCollection(name, { size : ..., cappe
首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇LevelDB数据库使用 下一篇SQL操作汇总

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Redis压力测试实战 - (2025-12-27 09:20:24)
·高并发一上来,微服 (2025-12-27 09:20:21)
·Redis 高可用架构深 (2025-12-27 09:20:18)
·Linux 系统监控 的完 (2025-12-27 08:52:29)
·一口气总结,25 个 L (2025-12-27 08:52:27)