MongoDB configuration

来源:互联网 发布:印度 人口 知乎 编辑:程序博客网 时间:2024/05/29 14:31
 
#https://docs.mongodb.org/manual/reference/configuration-options/systemLog:    verbosity: 0    quiet: true     traceAllExceptions: true    logRotate: "rename"    destination: file    path: "C:\\meteor\\logs\\Mongodb.log"    logAppend: true     timeStampFormat: "iso8601-local"    component:       accessControl:          verbosity: 0       command:          verbosity: 0       control:          verbosity: 0       geo:          verbosity: 0       index:          verbosity: 0       network:          verbosity: 0       query:          verbosity: 0       replication:          verbosity: 0       sharding:          verbosity: 0       storage:          verbosity: 0        write:          verbosity: 0 #processManagement:#   fork: false#   pidFilePath: "C:\\meteor\\db\\mongodb.pid" net:   port: 828   bindIp: 127.0.0.1   maxIncomingConnections: 65536   wireObjectCheck: true   ipv6: false#   unixDomainSocket:#      enabled: true#      pathPrefix: /tmp#      filePermissions: 0700   http:      enabled: false      JSONPEnabled: false      RESTInterfaceEnabled: false#   ssl:#      sslOnNormalPorts: <boolean>  # deprecated since 2.6#      mode: <string>#      PEMKeyFile: <string>#      PEMKeyPassword: <string>#      clusterFile: <string>#      clusterPassword: <string>#      CAFile: <string>#      CRLFile: <string>#      allowConnectionsWithoutCertificates: <boolean>#      allowInvalidCertificates: <boolean>#      allowInvalidHostnames: <boolean>#      disabledProtocols: <string>#      FIPSMode: <boolean>security:#   keyFile: ""my secret key""#   clusterAuthMode: keyFile   authorization: enabled # enabled disabled   javascriptEnabled:  true#   sasl:#      hostName: <string>#      serviceName: <string>#      saslauthdSocketPath: <string>#   enableEncryption: false#   encryptionCipherMode: "AES256-CBC"#   encryptionKeyFile: <string>#kmip:#      keyIdentifier: <string>#      rotateMasterKey: false#      serverName: <string>#      port: 5696#      clientCertificateFile: <string>#      clientCertificatePassword: <string>#      serverCAFile: <string>setParameter:   enableLocalhostAuthBypass: falsestorage:   dbPath: "C:\\meteor\\db"    indexBuildRetry: true   repairPath: "C:\\meteor\\db"   journal:      enabled: true #true on 64-bit systems, false on 32-bit systems      commitIntervalMs: 100   directoryPerDB: false   syncPeriodSecs: 60   engine: "wiredTiger"   mmapv1:       nsSize: 16      quota:         enforced: false         maxFilesPerDB: 8      smallFiles: false      journal:         debugFlags: 0    wiredTiger:      engineConfig:         cacheSizeGB: 5000         statisticsLogDelaySecs: 0         journalCompressor: "snappy" #none snappy zlib         directoryForIndexes: false      collectionConfig:         blockCompressor: "snappy"      indexConfig:         prefixCompression: trueoperationProfiling:   slowOpThresholdMs: 100   mode: "off"replication:#   oplogSizeMB: <int>#   replSetName: <string>   secondaryIndexPrefetch: "all"   enableMajorityReadConcern: false#   localPingThresholdMs: <boolean>#    localPingThresholdMs: 15sharding:#   clusterRole: <string> # configsvr shardsvr    archiveMovedChunks: false#    autoSplit: true#   configDB: <string>#   chunkSize: 64#auditLog:#   destination: <string> #syslog console file#   format: "JSON" #JSON #BSON#   path: <string>#   filter: <string>#snmp:#  subagent: <boolean>#  master: <boolean>#replication:#   localPingThresholdMs: <boolean>processManagement:   windowsService:      serviceName: "MongoDB"      displayName: "MongoDB"      description: "MongoDB Server  "#     serviceUser: <string>#     servicePassword: <string>



Mongodb to windowsServices

 sc.exe create MongoDB binPath= "\"C:\Program Files\MongoDB\Server\3.2\bin\mongod.exe\" --service --config=\"C:\MongoDB\mongodb.cfg\"" DisplayName= "MongoDB" start= "auto" 

 mongodb to nodejs


use admin db.createUser(  {     user: "sa",     pwd: "sa",     roles: [  { role: "read", db: "admin" }      ,{ role: "readWrite", db: "admin" }      ,{ role: "dbAdmin", db: "admin" }      ,{ role: "userAdmin", db: "admin" }      ,{ role: "clusterAdmin", db: "admin" }      ,{ role: "readAnyDatabase", db: "admin" }      ,{ role: "readWriteAnyDatabase", db: "admin" }      ,{ role: "userAdminAnyDatabase", db: "admin" }      ,{ role: "dbAdminAnyDatabase", db: "admin" } ]      })use test1db.createUser(   {     user: "test",     pwd: "pwd",     roles: ["read","readWrite","dbAdmin","userAdmin", "clusterAdmin","readAnyDatabase"     ,"readWriteAnyDatabase","userAdminAnyDatabase","dbAdminAnyDatabase"]   })var opts = { server: { auto_reconnect: false,native_parser:true },  db:{native_parser:true}, user: 'test', pass: 'pwd'}; var db=mongoose.createConnection(host,opts,function(err){    if (err) {        console.warn('can not connect',err);        console.warn(err);    } else {        console.log('connect .. '  );    }}); <pre name="code" class="javascript">var opts = { server: { auto_reconnect: false,native_parser:true },  db:{native_parser:true}, user: configData.user, pass: configData.pass};var db = mongoose.createConnection("127.0.0.1", "dbName:,27017, opts,function(err){    if (err) {        console.warn('can not connect',err);        console.warn(err);    } else {        console.log('connect .. host:'+configData.host+" port: "+configData.port);    }});




数据库备份还原

# mongorestore -d pictureAir --port 27017  /Users/DBServer/DBPathdir/ --drop# mongodump -d DBname -o /Users/DBServer/DBPathdir/# db.copyDatabase("dbname","dbname","127.0.0.1:27017");




0 0
原创粉丝点击