---
title: "mongodb笔记"
author: "heipark"
date: "2011-09-06T12:54:55Z"
tags: []
categories: ["数据库"]
slug: "mongodb"
draft: false
lastmod: "2012-10-29T10:23:39Z"
id: 1166516
url: "https://heipark.iteye.com/blog/1166516"
---

show dbs

show collections

use {database}

db.company.insert({"name":"A", age:27})

db.company.find()

db

db.{collection}.drop()

 

#创建数据库

先use {new\_DB}，然后insert data就可以了

 

\# 删除DB

use cc

db.dropDatabase()

 

\# find

db.boys.find()

 

db.boys.find({age: {$gt:30}}, {name:1, \_id:0})

db.boys.find({name:/^jice/})

db.boys.find().limit(1)

db.boys.find().limit(10).skip(5);

db.boys.find({$or: \[{age:88}, {age:28}]})

db.boys.findOne({name:"yue.zhang"})

 

 

\# 关闭Mongodb server

use admin

db.shutdownServer();

 

#shard

db.runCommand({ listshards: 1 })

db.printShardingStatus( true) 

 

use stat

db.pv.stats() 

 

\# 查看连接数

db.serverStatus().connections

\# 创建集合

db.createCollection("{collection\_name}")

 

\# 创建复合索引

db.province\_isp\_index.ensureIndex({"uid":1, "province" : 1, "isp" : 1})

 

 

PS：

&lt;!--\[if !supportLists]--&gt;1.       &lt;!--\[endif]--&gt;Shard模式下无法使用group命令

&lt;!--\[if !supportLists]--&gt;2.       &lt;!--\[endif]--&gt;group命令要求group by key数量不超过10000个，否则会报错

&lt;!--\[if !supportLists]--&gt;3.       &lt;!--\[endif]--&gt;无法同时group 和 count，官方建议将group结果拿到client端做count

 

参考：

#单机shard

[http://www.mongodb.org/display/DOCS/A+Sample+Configuration+Session](http://www.mongodb.org/display/DOCS/A+Sample+Configuration+Session)