Mogon - 简单操作

Ubuntu下操作mongoDB

配置局域网访问

sudo vi /etc/mongodb.conf


//修改bind_ip = 127.0.0.1

bind_ip = 0.0.0.0


重启服务

service mongodb restart

进入控制台

show dbs 显示数据库状况
gps 9.94921875GB
local   0.078125GB
stn 1.953125GB
 use gps – 类似选择数据库
switched to db gps
 显示当前操作数据库表单集合
show collections  
20150526
20150527
20150528
20150529
20150530
20150531
20150601
system.indexes
  db.stats() – 查询指定数据库统计信息
{
    "db" : "gps",
    "collections" : 9,
    "objects" : 16951372,
    "avgObjSize" : 271.95288994896697,
    "dataSize" : 4609974604,
    "storageSize" : 6048342016,
    "numExtents" : 125,
    "indexes" : 7,
    "indexSize" : 550105808,
    "fileSize" : 10666115072,
    "nsSizeMB" : 16,
    "dataFileVersion" : {
        "major" : 4,
        "minor" : 5
    },
    "ok" : 1
}
 插入数据到不存在的集合中
> show collections
20150526
20150527
20150528
20150529
20150530
20150531
20150601
system.indexes
> db.test.save({ad:123})
> show collections
20150526
20150527
20150528
20150529
20150530
20150531
20150601
system.indexes
test
> test.find()
Mon Jun  1 14:46:56.248 ReferenceError: test is not defined
> db.test.find()
{ "_id" : ObjectId("556bffd76597f2db2b00f4c4"), "ad" : 123 }
 删除数据库
> use stn
switched to db stn
> db.dropDatabase()
{ "dropped" : "stn", "ok" : 1 }
 显示数据库状态
> db.serverStatus()
{
    "host" : "ServerTest",
    "version" : "2.4.9",
    "process" : "mongod",
    "pid" : 12937,
    "uptime" : 502,
    "uptimeMillis" : NumberLong(501975),
    "uptimeEstimate" : 498,
    "localTime" : ISODate("2015-06-01T06:39:43.420Z"),
    "asserts" : {
        "regular" : 0,
        "warning" : 0,
        "msg" : 0,
        "user" : 0,
        "rollovers" : 0
    },
    "backgroundFlushing" : {
        "flushes" : 8,
        "total_ms" : 0,
        "average_ms" : 0,
        "last_ms" : 0,
        "last_finished" : ISODate("2015-06-01T06:39:21.469Z")
    },
    "connections" : {
        "current" : 1,
        "available" : 19999,
        "totalCreated" : NumberLong(4)
    },
    "cursors" : {
        "totalOpen" : 0,
        "clientCursors_size" : 0,
        "timedOut" : 0
    },
    "dur" : {
        "commits" : 30,
        "journaledMB" : 0,
        "writeToDataFilesMB" : 0,
        "compression" : 0,
        "commitsInWriteLock" : 0,
        "earlyCommits" : 0,
        "timeMs" : {
            "dt" : 3065,
            "prepLogBuffer" : 0,
            "writeToJournal" : 0,
            "writeToDataFiles" : 0,
            "remapPrivateView" : 0
        }
    },
    "extra_info" : {
        "note" : "fields vary by platform",
        "heap_usage_bytes" : 62677848,
        "page_faults" : 2
    },
    "globalLock" : {
        "totalTime" : NumberLong(501975000),
        "lockTime" : NumberLong(9625),
        "currentQueue" : {
            "total" : 0,
            "readers" : 0,
            "writers" : 0
        },
        "activeClients" : {
            "total" : 0,
            "readers" : 0,
            "writers" : 0
        }
    },
    "indexCounters" : {
        "accesses" : 0,
        "hits" : 0,
        "misses" : 0,
        "resets" : 0,
        "missRatio" : 0
    },
    "locks" : {
        "." : {
            "timeLockedMicros" : {
                "R" : NumberLong(4501),
                "W" : NumberLong(9625)
            },
            "timeAcquiringMicros" : {
                "R" : NumberLong(3113),
                "W" : NumberLong(456)
            }
        },
        "admin" : {
            "timeLockedMicros" : {

            },
            "timeAcquiringMicros" : {

            }
        },
        "local" : {
            "timeLockedMicros" : {
                "r" : NumberLong(1083),
                "w" : NumberLong(0)
            },
            "timeAcquiringMicros" : {
                "r" : NumberLong(67),
                "w" : NumberLong(0)
            }
        },
        "stn" : {
            "timeLockedMicros" : {
                "r" : NumberLong(262),
                "w" : NumberLong(0)
            },
            "timeAcquiringMicros" : {
                "r" : NumberLong(32),
                "w" : NumberLong(0)
            }
        },
        "gps" : {
            "timeLockedMicros" : {
                "r" : NumberLong(1956),
                "w" : NumberLong(0)
            },
            "timeAcquiringMicros" : {
                "r" : NumberLong(50),
                "w" : NumberLong(0)
            }
        }
    },
    "network" : {
        "bytesIn" : 1256,
        "bytesOut" : 2624,
        "numRequests" : 17
    },
    "opcounters" : {
        "insert" : 1,
        "query" : 26,
        "update" : 0,
        "delete" : 0,
        "getmore" : 0,
        "command" : 17
    },
    "opcountersRepl" : {
        "insert" : 0,
        "query" : 0,
        "update" : 0,
        "delete" : 0,
        "getmore" : 0,
        "command" : 0
    },
    "recordStats" : {
        "accessesNotInMemory" : 0,
        "pageFaultExceptionsThrown" : 0,
        "gps" : {
            "accessesNotInMemory" : 0,
            "pageFaultExceptionsThrown" : 0
        },
        "local" : {
            "accessesNotInMemory" : 0,
            "pageFaultExceptionsThrown" : 0
        },
        "stn" : {
            "accessesNotInMemory" : 0,
            "pageFaultExceptionsThrown" : 0
        }
    },
    "writeBacksQueued" : false,
    "mem" : {
        "bits" : 64,
        "resident" : 44,
        "virtual" : 18608,
        "supported" : true,
        "mapped" : 9197,
        "mappedWithJournal" : 18394
    },
    "metrics" : {
        "document" : {
            "deleted" : NumberLong(0),
            "inserted" : NumberLong(1),
            "returned" : NumberLong(30),
            "updated" : NumberLong(0)
        },
        "getLastError" : {
            "wtime" : {
                "num" : 0,
                "totalMillis" : 0
            },
            "wtimeouts" : NumberLong(0)
        },
        "operation" : {
            "fastmod" : NumberLong(0),
            "idhack" : NumberLong(0),
            "scanAndOrder" : NumberLong(0)
        },
        "queryExecutor" : {
            "scanned" : NumberLong(142)
        },
        "record" : {
            "moves" : NumberLong(0)
        },
        "repl" : {
            "apply" : {
                "batches" : {
                    "num" : 0,
                    "totalMillis" : 0
                },
                "ops" : NumberLong(0)
            },
            "buffer" : {
                "count" : NumberLong(0),
                "maxSizeBytes" : 268435456,
                "sizeBytes" : NumberLong(0)
            },
            "network" : {
                "bytes" : NumberLong(0),
                "getmores" : {
                    "num" : 0,
                    "totalMillis" : 0
                },
                "ops" : NumberLong(0),
                "readersCreated" : NumberLong(0)
            },
            "oplog" : {
                "insert" : {
                    "num" : 0,
                    "totalMillis" : 0
                },
                "insertBytes" : NumberLong(0)
            },
            "preload" : {
                "docs" : {
                    "num" : 0,
                    "totalMillis" : 0
                },
                "indexes" : {
                    "num" : 0,
                    "totalMillis" : 0
                }
            }
        },
        "ttl" : {
            "deletedDocuments" : NumberLong(0),
            "passes" : NumberLong(8)
        }
    },
    "ok" : 1
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值