用户工具

站点工具


docs:mongodb:usage_of_create_drop_update_query_mongodb

哈哈

以一下项目问题处理过程分析: 某项目的mongodb库名

环境

缘于项目,版本如下

[root@ mongodb]# /usr/local/mongodb/bin/mongo
MongoDB shell version v3.4.23
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.23
> db.help();
DB methods:
        db.adminCommand(nameOrDocument) - switches to 'admin' db, and runs command [ just calls db.runCommand(...) ]
        db.auth(username, password)
        db.cloneDatabase(fromhost)
        db.commandHelp(name) returns the help for the command
        db.copyDatabase(fromdb, todb, fromhost)
        db.createCollection(name, { size : ..., capped : ..., max : ... } )
        db.createView(name, viewOn, [ { $operator: {...}}, ... ], { viewOptions } )
        db.createUser(userDocument)
        db.currentOp() displays currently executing operations in the db
        db.dropDatabase()
        db.eval() - deprecated
        db.fsyncLock() flush data to disk and lock server for backups
        db.fsyncUnlock() unlocks server following a db.fsyncLock()
        db.getCollection(cname) same as db['cname'] or db.cname
        db.getCollectionInfos([filter]) - returns a list that contains the names and options of the db's collections
        db.getCollectionNames()
        db.getLastError() - just returns the err msg string
        db.getLastErrorObj() - return full status object
        db.getLogComponents()
        db.getMongo() get the server connection object
        db.getMongo().setSlaveOk() allow queries on a replication slave server
        db.getName()
        db.getPrevError()
        db.getProfilingLevel() - deprecated
        db.getProfilingStatus() - returns if profiling is on and slow threshold
        db.getReplicationInfo()
        db.getSiblingDB(name) get the db at the same server as this one
        db.getWriteConcern() - returns the write concern used for any operations on this db, inherited from server object if set
        db.hostInfo() get details about the server's host
        db.isMaster() check replica primary status
        db.killOp(opid) kills the current operation in the db
        db.listCommands() lists all the db commands
        db.loadServerScripts() loads all the scripts in db.system.js
        db.logout()
        db.printCollectionStats()
        db.printReplicationInfo()
        db.printShardingStatus()
        db.printSlaveReplicationInfo()
        db.dropUser(username)
        db.repairDatabase()
        db.resetError()
        db.runCommand(cmdObj) run a database command.  if cmdObj is a string, turns it into { cmdObj : 1 }
        db.serverStatus()
        db.setLogLevel(level,<component>)
        db.setProfilingLevel(level,<slowms>) 0=off 1=slow 2=all
        db.setWriteConcern( <write concern doc> ) - sets the write concern for writes to the db
        db.unsetWriteConcern( <write concern doc> ) - unsets the write concern for writes to the db
        db.setVerboseShell(flag) display extra information in shell output
        db.shutdownServer()
        db.stats()
        db.version() current version of the server
>

预览

> use admin
switched to db admin
> db.auth("useradmin","userpasswd")
1
> show dbs
admin                                              0.000GB
local                                              0.000GB
dbpro                                              0.000GB     {"新库,只有部分测试的数据。":""}
dbpro?authSource=admin&authMechanism=SCRAM-SHA-1   0.000GB     {"#数据主要存储在这里,估计是客户端程序连接时将参数传入(作为库名)创建相应的库。":""}

> db.MMInfoExtension.findOne()
null
> use dbpro 
switched to db dbpro 
> show tables
MMInfoExtension
>
> db.MMInfoExtension.findOne()
{
        "_id" : "282ec58a-66cd-4d48-a0ed-009f4fd180e2",
        "dd" : "22",
        "gcmc" : "测试**",
        "jsgq" : "2019-11-11",
        "bzdw" : "日照香炉服务*",
        "bh" : "37110020*********01",
        "operateusername" : "日照香炉服务",
        "sgfzr" : "**表单",
        "rowguid" : "282ec58a-66cd-4d48-a0ed-009f4fd180e2",
        "operatedate" : ISODate("2020-02-22T14:23:16.229Z"),
        "sgdw" : "侧啥",
        "certinfoguid" : "2e698446-ca14-4c67-9b6f-bfd5fb052433",
        "kcfzr" : "侧耳",
        "bz" : "",
        "kcdw" : "侧耳",
        "jsgm" : "12312.0m²",
        "sjdw" : "******建筑设计有限公司",
        "yy" : "2020",
        "mm" : "02",
        "ksgq" : "2018-11-11",
        "sjfzr" : "杨**",
        "jldw" : "121321312321231",
        "zjlgcs" : "大范围",
        "jsdw" : "**测试企业01",
        "jsdz" : "东至测试花园,西至测试花园,南至测试花园,北至测试花园",
        "htjg" : "312321",
        "jsfzr" : "发证人"
> use dbpro?authSource=admin&authMechanism=SCRAM-SHA-1 
switched to db dbpro?authSource=admin&authMechanism=SCRAM-SHA-1
> show tables
MMInfoExtension
>
> db.MMInfoExtension.findOne()
{
        "_id" : "38c5d7b0-e85f-4f8c-9e81-bde6f08a8b56",
        "dd" : "1",
        "gcmc" : "1",
        "jsgq" : "1",
        "bzdw" : "1",
        "bh" : "11",
        "operateusername" : "移动*****04",
        "sgfzr" : "1",
        "rowguid" : "38c5d7b0-e85f-4f8c-9e81-bde6f08a8b56",
        "operatedate" : ISODate("2019-12-19T12:52:11.210Z"),
        "sgdw" : "1",
        "certinfoguid" : "27132d8a-9bbd-466b-9d49-d6dd8c45f58f",
        "kcfzr" : "1",
        "bz" : "1",
        "kcdw" : "1",
        "jsgm" : "1",
        "sjdw" : "1",
        "yy" : "1",
        "mm" : "1",
        "ksgq" : "1",
        "sjfzr" : "1",
        "jldw" : "1",
        "zjlgcs" : "1",
        "jsdw" : "1",
        "jsdz" : "1",
        "zzlsh" : "1",
        "htjg" : "1",
        "jsfzr" : "1"
}

> use admin
switched to db admin
> db.runCommand({renameCollection:"dbpro?authSource=admin&authMechanism=SCRAM-SHA-1.MMInfoExtension", to:"test.MMInfoExtension"})
{"ok" : 1 }
{"这里利用了长名称可以移动其内部集合的功能,先将集合移出,使其在新库test中可以正常导出或备份" : "然后还可以反向还原回去。json备注(只是为了高亮)" }

> show dbs
admin                                              0.000GB
local                                              0.000GB
dbpro                                              0.000GB
dbpro?authSource=admin&authMechanism=SCRAM-SHA-1   0.000GB
test                                               0.000GB
> show collections
system.users
system.version
> use test
switched to db test
> show collections
MMInfoExtension
> db.MMInfoExtension.findOne()
{
        "_id" : "38c5d7b0-e85f-4f8c-9e81-bde6f08a8b56",
        "dd" : "1",
        "gcmc" : "1",
        "jsgq" : "1",
        "bzdw" : "1",
        "bh" : "11",
        "operateusername" : "移动*****04",
        "sgfzr" : "1",
        "rowguid" : "38c5d7b0-e85f-4f8c-9e81-bde6f08a8b56",
        "operatedate" : ISODate("2019-12-19T12:52:11.210Z"),
        "sgdw" : "1",
        "certinfoguid" : "27132d8a-9bbd-466b-9d49-d6dd8c45f58f",
        "kcfzr" : "1",
        "bz" : "1",
        "kcdw" : "1",
        "jsgm" : "1",
        "sjdw" : "1",
        "yy" : "1",
        "mm" : "1",
        "ksgq" : "1",
        "sjfzr" : "1",
        "jldw" : "1",
        "zjlgcs" : "1",
        "jsdw" : "1",
        "jsdz" : "1",
        "zzlsh" : "1",
        "htjg" : "1",
        "jsfzr" : "1"
}
> db.MMInfoExtension.find({"mm":"9"}).count()
0
> db.MMInfoExtension.find({"mm":"1"}).count()
113
>

状态查询

[root@mhanode102 mongodb]# du -sh ../mongodb/data/*
156K    ../mongodb/data/admin
166M    ../mongodb/data/diagnostic.data
300M    ../mongodb/data/journal
72K     ../mongodb/data/local
36K     ../mongodb/data/_mdb_catalog.wt
4.0K    ../mongodb/data/mongod.lock
104K    ../mongodb/data/dbpro
116K    ../mongodb/data/dbpro.63authSource.61admin.38authMechanism.61SCRAM.45SHA.451
36K     ../mongodb/data/sizeStorer.wt
4.0K    ../mongodb/data/storage.bson
276K    ../mongodb/data/test
4.0K    ../mongodb/data/WiredTiger
4.0K    ../mongodb/data/WiredTigerLAS.wt
4.0K    ../mongodb/data/WiredTiger.lock
4.0K    ../mongodb/data/WiredTiger.turtle
92K     ../mongodb/data/WiredTiger.wt
存储引擎(Storage Engine) 是MongoDB的核心组件,负责管理数据如何存储在硬盘(Disk)和内存(Memory)上。从MongoDB 3.2 版本开始,MongoDB 支持多数据存储引擎(Storage Engine),MongoDB支持的存储引擎有:WiredTiger,MMAPv1和In-Memory。https://www.cnblogs.com/ljhdo/archive/2016/10/30/4947357.html

从MongoDB 3.2 版本开始,WiredTiger成为MongDB默认的Storage Engine,用于将数据持久化存储到硬盘文件中,WiredTiger提供文档级别(Document-Level)的并发控制,检查点(CheckPoint),数据压缩和本地数据加密( Native Encryption)等功能。
MongoDB不仅能将数据持久化存储到硬盘文件中,而且还能将数据只保存到内存中;In-Memory存储引擎用于将数据只存储在内存中,只将少量的元数据和诊断日志(Diagnostic)存储到硬盘文件中,由于不需要Disk的IO操作,就能获取索取的数据,In-Memory存储引擎大幅度降低了数据查询的延迟(Latency)。

> db.stats()
{
        "db" : "test",
        "collections" : 1,
        "views" : 0,
        "objects" : 395,
        "avgObjSize" : 637.5012658227848,
        "dataSize" : 251813,
        "storageSize" : 106496,
        "numExtents" : 0,
        "indexes" : 1,
        "indexSize" : 32768,
        "ok" : 1
}
> 

docs/mongodb/usage_of_create_drop_update_query_mongodb.txt · 最后更改: 2020/09/25 21:49 (modify by Amos)