MongoDB笔记

与SQL相比

请提供一个中文的上下文。

    • /etc/mongodb.conf

 

    • /etc/init.d/mongodb

 

    /var/log/mongodb/mongodb.log

mongostat是一个命令行工具。

$ mongostat 
connected to: 127.0.0.1
insert  query update delete getmore command flushes mapped  vsize    res faults  locked db idx miss %     qr|qw   ar|aw  netIn netOut  conn       time 
     0      0      0      0       0       1       0    80m   347m    33m      0  test:0.0%          0       0|0     0|0    62b     1k     1   15:48:17 
     0      0      0      0       0       1       0    80m   347m    33m      0  test:0.0%          0       0|0     0|0    62b     1k     1   15:48:18 
     0      0      0      0       0       1       0    80m   347m    33m      0  test:0.0%          0       0|0     0|0    62b     1k     1   15:48:19 
     0      0      0      0       0       1       0    80m   347m    33m      0  test:0.0%          0       0|0     0|0    62b     1k     

游戏机

> 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 dbs
local   (empty)
> use local
switched to db local
> db.local.find()
> use test
switched to db test
> db.col.save({A:1});
> db.col.find();
{ "_id" : ObjectId("52146053f1cf872b926ddab2"), "A" : 1 }
> db.col.count();
1
> db.col.save({B:2});
> db.col.save({C:5});
> db.col.find();
{ "_id" : ObjectId("52146053f1cf872b926ddab2"), "A" : 1 }
{ "_id" : ObjectId("5214606cf1cf872b926ddab3"), "B" : 2 }
{ "_id" : ObjectId("5214606ff1cf872b926ddab4"), "C" : 5 }
> db.col.find({B:2});
{ "_id" : ObjectId("5214606cf1cf872b926ddab3"), "B" : 2 }
> db.col.remove({"C":5})
> db.col.find();
{ "_id" : ObjectId("52146053f1cf872b926ddab2"), "A" : 1 }
{ "_id" : ObjectId("5214606cf1cf872b926ddab3"), "B" : 2 }
> db.col.save({ "first_name" : "Jane", "last_name" : "Doe", "age" : 23  });
> db.col.find();
{ "_id" : ObjectId("52146053f1cf872b926ddab2"), "A" : 1 }
{ "_id" : ObjectId("5214606cf1cf872b926ddab3"), "B" : 2 }
{ "_id" : ObjectId("521460a6f1cf872b926ddab5"), "first_name" : "Jane", "last_name" : "Doe", "age" : 23 }