2013-12-02 16:19:30 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-01 16:59:04 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								'use strict' ;  
						 
					
						
							
								
									
										
										
										
											2013-12-02 16:19:30 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-10-03 16:31:53 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-08-06 18:27:00 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								const  winston  =  require ( 'winston' ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								const  nconf  =  require ( 'nconf' ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								const  session  =  require ( 'express-session' ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								const  semver  =  require ( 'semver' ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								const  prompt  =  require ( 'prompt' ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								const  utils  =  require ( '../utils' ) ;  
						 
					
						
							
								
									
										
										
										
											2017-04-22 00:19:23 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-08-06 17:35:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								let  client ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-08-06 18:27:00 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								const  connection  =  require ( './mongo/connection' ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								const  mongoModule  =  module . exports ;  
						 
					
						
							
								
									
										
										
										
											2017-04-22 00:19:23 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-23 15:09:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								function  isUriNotSpecified ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  ! prompt . history ( 'mongo:uri' ) . value ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-04-22 00:19:23 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								mongoModule . questions  =  [  
						 
					
						
							
								
									
										
										
										
											2017-10-23 15:09:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										name :  'mongo:uri' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										description :  'MongoDB connection URI: (leave blank if you wish to specify host, port, username/password and database individually)\nFormat: mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										default :  nconf . get ( 'mongo:uri' )  ||  '' , 
							 
						 
					
						
							
								
									
										
										
										
											2017-11-22 12:19:08 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										hideOnWebInstall :  true , 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-23 15:09:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} , 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-22 00:19:23 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										name :  'mongo:host' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										description :  'Host IP or address of your MongoDB instance' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										default :  nconf . get ( 'mongo:host' )  ||  '127.0.0.1' , 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-23 15:09:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										ask :  isUriNotSpecified , 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-22 00:19:23 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										name :  'mongo:port' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										description :  'Host port of your MongoDB instance' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										default :  nconf . get ( 'mongo:port' )  ||  27017 , 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-23 15:09:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										ask :  isUriNotSpecified , 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-22 00:19:23 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										name :  'mongo:username' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										description :  'MongoDB username' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										default :  nconf . get ( 'mongo:username' )  ||  '' , 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-23 15:09:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										ask :  isUriNotSpecified , 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-22 00:19:23 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										name :  'mongo:password' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										description :  'Password of your MongoDB database' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										default :  nconf . get ( 'mongo:password' )  ||  '' , 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-23 15:09:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										hidden :  true , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ask :  isUriNotSpecified , 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-22 00:19:23 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										before :  function  ( value )  {  value  =  value  ||  nconf . get ( 'mongo:password' )  ||  '' ;  return  value ;  } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										name :  'mongo:database' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										description :  'MongoDB database name' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										default :  nconf . get ( 'mongo:database' )  ||  'nodebb' , 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-23 15:09:13 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										ask :  isUriNotSpecified , 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-22 00:19:23 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								] ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-03 22:26:33 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								mongoModule . init  =  async  function  ( )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									client  =  await  connection . connect ( nconf . get ( 'mongo' ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									mongoModule . client  =  client . db ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-22 00:19:23 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} ;  
						 
					
						
							
								
									
										
										
										
											2017-01-11 10:51:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-03 22:26:33 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								mongoModule . createSessionStore  =  async  function  ( options )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									const  client  =  await  connection . connect ( options ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									const  meta  =  require ( '../meta' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									const  sessionStore  =  require ( 'connect-mongo' ) ( session ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									const  store  =  new  sessionStore ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										client :  client , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ttl :  meta . getSessionTTLSeconds ( ) , 
							 
						 
					
						
							
								
									
										
										
										
											2018-11-24 23:02:22 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-22 00:19:23 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-03 22:26:33 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  store ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;  
						 
					
						
							
								
									
										
										
										
											2017-04-22 00:19:23 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-03 22:26:33 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								mongoModule . createIndices  =  async  function  ( )  {  
						 
					
						
							
								
									
										
										
										
											2017-04-22 00:19:23 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( ! mongoModule . client )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										winston . warn ( '[database/createIndices] database not initialized' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-03 22:26:33 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-22 00:19:23 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									winston . info ( '[database] Checking database indices.' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-03 22:26:33 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									const  collection  =  mongoModule . client . collection ( 'objects' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									await  collection . createIndex ( {  _key :  1 ,  score :  - 1  } ,  {  background :  true  } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									await  collection . createIndex ( {  _key :  1 ,  value :  - 1  } ,  {  background :  true ,  unique :  true ,  sparse :  true  } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									await  collection . createIndex ( {  expireAt :  1  } ,  {  expireAfterSeconds :  0 ,  background :  true  } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									winston . info ( '[database] Checking database indices done!' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-22 00:19:23 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								mongoModule . checkCompatibility  =  function  ( callback )  {  
						 
					
						
							
								
									
										
										
										
											2019-10-03 22:26:33 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									const  mongoPkg  =  require ( 'mongodb/package.json' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-19 20:24:54 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									mongoModule . checkCompatibilityVersion ( mongoPkg . version ,  callback ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;  
						 
					
						
							
								
									
										
										
										
											2017-04-22 00:19:23 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-05-19 20:24:54 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								mongoModule . checkCompatibilityVersion  =  function  ( version ,  callback )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( semver . lt ( version ,  '2.0.0' ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-22 00:19:23 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  callback ( new  Error ( 'The `mongodb` package is out-of-date, please run `./nodebb setup` again.' ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									callback ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-03 22:26:33 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								mongoModule . info  =  async  function  ( db )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! db )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										const  client  =  await  connection . connect ( nconf . get ( 'mongo' ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										db  =  client . db ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									mongoModule . client  =  mongoModule . client  ||  db ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-30 15:23:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									let  serverStatusError  =  '' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									async  function  getServerStatus ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										try  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  await  db . command ( {  serverStatus :  1  } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										}  catch  ( err )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											serverStatusError  =  err . message ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											// Override mongo error with more human-readable error
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( err . name  ===  'MongoError'  &&  err . codeName  ===  'Unauthorized' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												serverStatusError  =  '[[admin/advanced/database:mongo.unauthorized]]' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											winston . error ( err . stack ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-03 22:26:33 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									let  [ serverStatus ,  stats ,  listCollections ]  =  await  Promise . all ( [ 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-30 15:23:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										getServerStatus ( ) , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-03 22:26:33 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										db . command ( {  dbStats :  1  } ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										getCollectionStats ( db ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									] ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									stats  =  stats  ||  { } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									serverStatus  =  serverStatus  ||  { } ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-30 15:23:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									stats . serverStatusError  =  serverStatusError ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-03 22:26:33 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									const  scale  =  1024  *  1024  *  1024 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									listCollections  =  listCollections . map ( function  ( collectionInfo )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											name :  collectionInfo . ns , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											count :  collectionInfo . count , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											size :  collectionInfo . size , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											avgObjSize :  collectionInfo . avgObjSize , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											storageSize :  collectionInfo . storageSize , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											totalIndexSize :  collectionInfo . totalIndexSize , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											indexSizes :  collectionInfo . indexSizes , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-30 15:23:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									stats . mem  =  serverStatus . mem  ||  {  resident :  0 ,  virtual :  0 ,  mapped :  0  } ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-03 22:26:33 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									stats . mem . resident  =  ( stats . mem . resident  /  1024 ) . toFixed ( 3 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									stats . mem . virtual  =  ( stats . mem . virtual  /  1024 ) . toFixed ( 3 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									stats . mem . mapped  =  ( stats . mem . mapped  /  1024 ) . toFixed ( 3 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									stats . collectionData  =  listCollections ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-11-30 15:23:37 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									stats . network  =  serverStatus . network  ||  {  bytesIn :  0 ,  bytesOut :  0 ,  numRequests :  0  } ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-03 22:26:33 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									stats . network . bytesIn  =  ( stats . network . bytesIn  /  scale ) . toFixed ( 3 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									stats . network . bytesOut  =  ( stats . network . bytesOut  /  scale ) . toFixed ( 3 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									stats . network . numRequests  =  utils . addCommas ( stats . network . numRequests ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									stats . raw  =  JSON . stringify ( stats ,  null ,  4 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									stats . avgObjSize  =  stats . avgObjSize . toFixed ( 2 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									stats . dataSize  =  ( stats . dataSize  /  scale ) . toFixed ( 3 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									stats . storageSize  =  ( stats . storageSize  /  scale ) . toFixed ( 3 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									stats . fileSize  =  stats . fileSize  ?  ( stats . fileSize  /  scale ) . toFixed ( 3 )  :  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									stats . indexSize  =  ( stats . indexSize  /  scale ) . toFixed ( 3 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									stats . storageEngine  =  serverStatus . storageEngine  ?  serverStatus . storageEngine . name  :  'mmapv1' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									stats . host  =  serverStatus . host ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									stats . version  =  serverStatus . version ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									stats . uptime  =  serverStatus . uptime ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									stats . mongo  =  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  stats ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-22 00:19:23 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-03 22:26:33 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								async  function  getCollectionStats ( db )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									const  items  =  await  db . listCollections ( ) . toArray ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-06 22:08:52 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  await  Promise . all ( items . map ( collection  =>  db . collection ( collection . name ) . stats ( ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-19 20:24:54 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								mongoModule . close  =  function  ( callback )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									callback  =  callback  ||  function  ( )  { } ; 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-03 22:26:33 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									client . close ( err  =>  callback ( err ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-22 00:19:23 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} ;  
						 
					
						
							
								
									
										
										
										
											2018-01-18 12:02:56 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-08-05 09:20:00 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								require ( './mongo/main' ) ( mongoModule ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								require ( './mongo/hash' ) ( mongoModule ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								require ( './mongo/sets' ) ( mongoModule ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								require ( './mongo/sorted' ) ( mongoModule ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								require ( './mongo/list' ) ( mongoModule ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								require ( './mongo/transaction' ) ( mongoModule ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-24 12:02:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								require ( '../promisify' ) ( mongoModule ,  [ 'client' ,  'sessionStore' ] ) ;