4.3BSON
BSON是一种类似于json的二进制的存储格式,Binary JSON,支持内建的文档对象和数组对象,并且包含JSON所没有的一些数据类型。MongoDB采用BSON这种结构来存储数据和进行网络数据交换,把这个格式转化成Document的概念,由于BSON是模式自由的,所以document也是模式自由的。
5.mongodb的简单操作:
[iyunv@localhost ~]# mongo
> help
db.help() help on db methods
db.mycoll.help() help on collection methods
sh.help() sharding helpers
rs.help() replica set helpers
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 with time >= 1ms
show logs show the accessible logger names
show log [name] prints out the last segment of log in memory, 'global' is default
use <db_name> 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 evaluated; use to further iterate
DBQuery.shellBatchSize = x set default number of items to display on shell
exit quit the mongo shell
> show users
> show profile
db.system.profile is empty
Use db.setProfilingLevel(2) will enable profiling
Use db.system.profile.find() to show raw profile entries
#列出当前有哪些数据库
> show dbs;
local 0.078GB
> db.test_1.save({1:"AAA"});
WriteResult({ "nInserted" : 1 })
> db.test_1.save({2:"BBB"});
WriteResult({ "nInserted" : 1 })
> db.test_1.find();
{ "_id" : ObjectId("556d171a75f85e97eeec2f5b"), "1" : "AAA" }
{ "_id" : ObjectId("556d172375f85e97eeec2f5c"), "2" : "BBB" }
> show dbs;
local 0.078GB
test 0.078GB
#查看当前的数据库
> db
test
#列出当前数据库中有哪些集合
> show collections
system.indexes
test_1
6.关闭mongodb:
[iyunv@localhost ~]# mongo
> use admin
switched to db admin
> db.shutdownServer();
2015-06-01T19:35:45.155-0700 I NETWORK DBClientCursor::init call() failed
server should be down...
2015-06-01T19:35:45.159-0700 I NETWORK trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed
2015-06-01T19:35:45.159-0700 W NETWORK Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2015-06-01T19:35:45.160-0700 I NETWORK reconnect 127.0.0.1:27017 (127.0.0.1) failed failed couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed