程序地带

关于docker安装创建mongodb并且测试代码


docker 安装mongodb-创建用户
 docker run -itd --name mongo -p 27017:27017 mongo --auth

进入数据库添加密码


https://unsplash.com/collections/65033833https://unsplash.com/collections/89931451https://unsplash.com/collections/86572748https://unsplash.com/collections/23891973https://unsplash.com/collections/36714792https://unsplash.com/collections/84571638https://unsplash.com/collections/42505270https://unsplash.com/collections/21807062https://unsplash.com/collections/40091997https://unsplash.com/collections/55660318https://unsplash.com/collections/91073320https://unsplash.com/collections/66181831https://unsplash.com/collections/54244588https://unsplash.com/collections/20818407https://unsplash.com/collections/93544575https://unsplash.com/collections/46670682https://unsplash.com/collections/49850784https://unsplash.com/collections/52228423https://unsplash.com/collections/59407587https://unsplash.com/collections/33342445https://unsplash.com/collections/68152646https://unsplash.com/collections/55670978https://unsplash.com/collections/19302339https://unsplash.com/collections/72775014https://unsplash.com/collections/38328429https://unsplash.com/collections/79525907https://unsplash.com/collections/31890953https://unsplash.com/collections/37028666https://unsplash.com/collections/61390772https://unsplash.com/collections/22532042https://unsplash.com/collections/65105270https://unsplash.com/collections/13143975https://unsplash.com/collections/85249501https://unsplash.com/collections/37135305https://unsplash.com/collections/78888775https://unsplash.com/collections/15926676https://unsplash.com/collections/14809683https://unsplash.com/collections/72007278https://unsplash.com/collections/61484419https://unsplash.com/collections/57419486https://unsplash.com/collections/29852348https://unsplash.com/collections/41940539https://unsplash.com/collections/72815268https://unsplash.com/collections/25343604https://unsplash.com/collections/39914154https://unsplash.com/collections/86269352https://unsplash.com/collections/82479764https://unsplash.com/collections/94616024https://unsplash.com/collections/92906151https://unsplash.com/collections/89978255https://unsplash.com/collections/94543808https://unsplash.com/collections/79290838https://unsplash.com/collections/48504966https://unsplash.com/collections/42903523https://unsplash.com/collections/28292159https://unsplash.com/collections/98113064https://unsplash.com/collections/69444834https://unsplash.com/collections/75059663https://unsplash.com/collections/51992006https://unsplash.com/collections/13369084https://unsplash.com/collections/67891482https://unsplash.com/collections/61875439https://unsplash.com/collections/27233682https://unsplash.com/collections/47700809https://unsplash.com/collections/98205154https://unsplash.com/collections/69559007https://unsplash.com/collections/44499282https://unsplash.com/collections/19693065https://unsplash.com/collections/64697097https://unsplash.com/collections/46758933https://unsplash.com/collections/31275516https://unsplash.com/collections/21605695https://unsplash.com/collections/33092357https://unsplash.com/collections/34045468https://unsplash.com/collections/71812532https://unsplash.com/collections/50482794https://unsplash.com/collections/72394929https://unsplash.com/collections/94832256https://unsplash.com/collections/89361499https://unsplash.com/collections/43559528https://unsplash.com/collections/51242709https://unsplash.com/collections/47941916https://unsplash.com/collections/22892756https://unsplash.com/collections/74389830https://unsplash.com/collections/55200631https://unsplash.com/collections/84583760https://unsplash.com/collections/74788095https://unsplash.com/collections/24638524https://unsplash.com/collections/57924929https://unsplash.com/collections/42936878https://unsplash.com/collections/25257414https://unsplash.com/collections/27835604https://unsplash.com/collections/55543092https://unsplash.com/collections/90986194https://unsplash.com/collections/56595353https://unsplash.com/collections/49086146https://unsplash.com/collections/89150825https://unsplash.com/collections/28120854https://unsplash.com/collections/88664190https://unsplash.com/collections/62771969https://unsplash.com/collections/20643242https://unsplash.com/collections/97750770https://unsplash.com/collections/43856502https://unsplash.com/collections/47769586https://unsplash.com/collections/67094088https://unsplash.com/collections/82929948https://unsplash.com/collections/62262534https://unsplash.com/collections/13193019https://unsplash.com/collections/74215040https://unsplash.com/collections/46097481https://unsplash.com/collections/67145041https://unsplash.com/collections/30688710https://unsplash.com/collections/73089384https://unsplash.com/collections/82516853https://unsplash.com/collections/20558500https://unsplash.com/collections/32733674https://unsplash.com/collections/78855288https://unsplash.com/collections/93741170https://unsplash.com/collections/61269351https://unsplash.com/collections/65534146https://unsplash.com/collections/34250355https://unsplash.com/collections/28460536https://unsplash.com/collections/30645788https://unsplash.com/collections/88064669https://unsplash.com/collections/65729547https://unsplash.com/collections/73172374https://unsplash.com/collections/97101927https://unsplash.com/collections/26638389https://unsplash.com/collections/37376575https://unsplash.com/collections/76955658https://unsplash.com/collections/68093533https://unsplash.com/collections/52234647https://unsplash.com/collections/75772003https://unsplash.com/collections/23019966https://unsplash.com/collections/31304203https://unsplash.com/collections/71302292https://unsplash.com/collections/51703260https://unsplash.com/collections/63758724https://unsplash.com/collections/60998464https://unsplash.com/collections/31804895https://unsplash.com/collections/55129631https://unsplash.com/collections/69040299https://unsplash.com/collections/29502084https://unsplash.com/collections/95659535https://unsplash.com/collections/51616286https://unsplash.com/collections/57451334https://unsplash.com/collections/65724480https://unsplash.com/collections/81906664https://unsplash.com/collections/47814211https://unsplash.com/collections/64139637https://unsplash.com/collections/14788168https://unsplash.com/collections/74968421https://unsplash.com/collections/86131458https://unsplash.com/collections/85093295https://unsplash.com/collections/61727849https://unsplash.com/collections/76209227https://unsplash.com/collections/48898487https://unsplash.com/collections/82347886https://unsplash.com/collections/33928706https://unsplash.com/collections/87972469https://unsplash.com/collections/76954969https://unsplash.com/collections/17057721https://unsplash.com/collections/90699534https://unsplash.com/collections/21873675https://unsplash.com/collections/43146389https://unsplash.com/collections/19812979https://unsplash.com/collections/33419441https://unsplash.com/collections/57013668https://unsplash.com/collections/13290829https://unsplash.com/collections/32179559https://unsplash.com/collections/81469985https://unsplash.com/collections/59823483https://unsplash.com/collections/88861620https://unsplash.com/collections/51796205https://unsplash.com/collections/46976765https://unsplash.com/collections/42694664https://unsplash.com/collections/48284779https://unsplash.com/collections/54372294https://unsplash.com/collections/54613589https://unsplash.com/collections/82147417https://unsplash.com/collections/88429231https://unsplash.com/collections/54170803https://unsplash.com/collections/95487449https://unsplash.com/collections/19319604https://unsplash.com/collections/60834840https://unsplash.com/collections/78713635https://unsplash.com/collections/80871998https://unsplash.com/collections/15850451https://unsplash.com/collections/80341724https://unsplash.com/collections/44392430https://unsplash.com/collections/68231338https://unsplash.com/collections/97320984https://unsplash.com/collections/40083477https://unsplash.com/collections/99950107https://unsplash.com/collections/40634000https://unsplash.com/collections/82501674https://unsplash.com/collections/19744322https://unsplash.com/collections/38872704https://unsplash.com/collections/56130780https://unsplash.com/collections/93560302https://unsplash.com/collections/89062289https://unsplash.com/collections/65053873https://unsplash.com/collections/81815082https://unsplash.com/collections/29303606https://unsplash.com/collections/36277596https://unsplash.com/collections/99718788https://unsplash.com/collections/27929978https://unsplash.com/collections/36997418https://unsplash.com/collections/34617697https://unsplash.com/collections/69187347https://unsplash.com/collections/24122795https://unsplash.com/collections/47593905https://unsplash.com/collections/37235919https://unsplash.com/collections/67154554https://unsplash.com/collections/24205463https://unsplash.com/collections/31668824https://unsplash.com/collections/37919659https://unsplash.com/collections/14408895https://unsplash.com/collections/88039310https://unsplash.com/collections/94241966https://unsplash.com/collections/46966528https://unsplash.com/collections/77953177https://unsplash.com/collections/43421936https://unsplash.com/collections/87886617https://unsplash.com/collections/25570769https://unsplash.com/collections/87693230https://unsplash.com/collections/97039556https://unsplash.com/collections/68025306https://unsplash.com/collections/37413643https://unsplash.com/collections/28751377https://unsplash.com/collections/40480993https://unsplash.com/collections/81979947https://unsplash.com/collections/95811452https://unsplash.com/collections/66638053https://unsplash.com/collections/33330715https://unsplash.com/collections/67332301https://unsplash.com/collections/50091061https://unsplash.com/collections/73727154https://unsplash.com/collections/59391936https://unsplash.com/collections/45269686https://unsplash.com/collections/70076849https://unsplash.com/collections/38773165https://unsplash.com/collections/38764653https://unsplash.com/collections/51301762https://unsplash.com/collections/44375178https://unsplash.com/collections/53718134https://unsplash.com/collections/91742674https://unsplash.com/collections/47796556https://unsplash.com/collections/60715540https://unsplash.com/collections/70460982https://unsplash.com/collections/40268557https://unsplash.com/collections/31614340https://unsplash.com/collections/50474167https://unsplash.com/collections/21975754https://unsplash.com/collections/51066315https://unsplash.com/collections/81944456https://unsplash.com/collections/70159855https://unsplash.com/collections/96249288https://unsplash.com/collections/47014706https://unsplash.com/collections/74562707https://unsplash.com/collections/38161578https://unsplash.com/collections/42480460https://unsplash.com/collections/59997488https://unsplash.com/collections/89306452https://unsplash.com/collections/75388918https://unsplash.com/collections/72822798https://unsplash.com/collections/79270349https://unsplash.com/collections/63994115https://unsplash.com/collections/91585362https://unsplash.com/collections/59777203https://unsplash.com/collections/29872836https://unsplash.com/collections/48252777https://unsplash.com/collections/80469922https://unsplash.com/collections/60699869https://unsplash.com/collections/88113001https://unsplash.com/collections/87375113https://unsplash.com/collections/61997425https://unsplash.com/collections/69865284https://unsplash.com/collections/34143613https://unsplash.com/collections/55564098https://unsplash.com/collections/20380751https://unsplash.com/collections/57306954https://unsplash.com/collections/53394362https://unsplash.com/collections/49626393https://unsplash.com/collections/68640030https://unsplash.com/collections/96289287https://unsplash.com/collections/73303050https://unsplash.com/collections/53934503https://unsplash.com/collections/81216332https://unsplash.com/collections/13211247https://unsplash.com/collections/92667626https://unsplash.com/collections/60853217https://unsplash.com/collections/76552802https://unsplash.com/collections/40765804https://unsplash.com/collections/71787513https://unsplash.com/collections/52018195https://unsplash.com/collections/36955599https://unsplash.com/collections/38953468https://unsplash.com/collections/61135934https://unsplash.com/collections/39404542https://unsplash.com/collections/99013929https://unsplash.com/collections/17540126https://unsplash.com/collections/48964606https://unsplash.com/collections/75923988https://unsplash.com/collections/86758259https://unsplash.com/collections/34304066https://unsplash.com/collections/20104271https://unsplash.com/collections/99639423https://unsplash.com/collections/51003615https://unsplash.com/collections/35882101https://unsplash.com/collections/93653741https://unsplash.com/collections/93880889https://unsplash.com/collections/66233727https://unsplash.com/collections/18323871https://unsplash.com/collections/53411964https://unsplash.com/collections/44937756https://unsplash.com/collections/39085417https://unsplash.com/collections/30869243https://unsplash.com/collections/67799129https://unsplash.com/collections/65153283https://unsplash.com/collections/91200846https://unsplash.com/collections/22586622https://unsplash.com/collections/28759996https://unsplash.com/collections/53698863https://unsplash.com/collections/44860009https://unsplash.com/collections/68768164https://unsplash.com/collections/30740498https://unsplash.com/collections/95726183https://unsplash.com/collections/16378962https://unsplash.com/collections/93807670https://unsplash.com/collections/26469625https://unsplash.com/collections/15798468https://unsplash.com/collections/30085224https://unsplash.com/collections/87516136https://unsplash.com/collections/59288720https://unsplash.com/collections/22465936https://unsplash.com/collections/32164281https://unsplash.com/collections/37294906https://unsplash.com/collections/44109140https://unsplash.com/collections/76976873https://unsplash.com/collections/66002422https://unsplash.com/collections/76173950https://unsplash.com/collections/31415969https://unsplash.com/collections/46753659https://unsplash.com/collections/53025399https://unsplash.com/collections/34044676https://unsplash.com/collections/39962486https://unsplash.com/collections/33820792https://unsplash.com/collections/14900742https://unsplash.com/collections/71951043https://unsplash.com/collections/93540819https://unsplash.com/collections/35796777https://unsplash.com/collections/29633572https://unsplash.com/collections/26154429https://unsplash.com/collections/70161364https://unsplash.com/collections/23131157https://unsplash.com/collections/21372788https://unsplash.com/collections/71186284https://unsplash.com/collections/69596213https://unsplash.com/collections/87723863https://unsplash.com/collections/44850247https://unsplash.com/collections/38043048https://unsplash.com/collections/48887564https://unsplash.com/collections/69993253https://unsplash.com/collections/58243786https://unsplash.com/collections/47041898https://unsplash.com/collections/64309910https://unsplash.com/collections/16807321https://unsplash.com/collections/30485871https://unsplash.com/collections/55353672https://unsplash.com/collections/25965125https://unsplash.com/collections/24531238https://unsplash.com/collections/19407988https://unsplash.com/collections/52775468https://unsplash.com/collections/65007177https://unsplash.com/collections/86801133https://unsplash.com/collections/48878812https://unsplash.com/collections/87316557https://unsplash.com/collections/86872996https://unsplash.com/collections/32962239https://unsplash.com/collections/18014693https://unsplash.com/collections/26636301https://unsplash.com/collections/58019620https://unsplash.com/collections/40969272https://unsplash.com/collections/40060175https://unsplash.com/collections/45282537https://unsplash.com/collections/33007616https://unsplash.com/collections/50652458https://unsplash.com/collections/34695314https://unsplash.com/collections/80856636https://unsplash.com/collections/91526539https://unsplash.com/collections/31882578https://unsplash.com/collections/57826716https://unsplash.com/collections/57727653https://unsplash.com/collections/98085520https://unsplash.com/collections/61325204https://unsplash.com/collections/43029115https://unsplash.com/collections/73272497https://unsplash.com/collections/42451823https://unsplash.com/collections/39442246https://unsplash.com/collections/15649506https://unsplash.com/collections/82829364https://unsplash.com/collections/26140491https://unsplash.com/collections/56741087https://unsplash.com/collections/92925667https://unsplash.com/collections/49443649https://unsplash.com/collections/62438216https://unsplash.com/collections/59700943https://unsplash.com/collections/25014855https://unsplash.com/collections/50518082https://unsplash.com/collections/69025398https://unsplash.com/collections/26037990https://unsplash.com/collections/49336158https://unsplash.com/collections/15907536https://unsplash.com/collections/26555492https://unsplash.com/collections/14871438https://unsplash.com/collections/66521947https://unsplash.com/collections/69247056https://unsplash.com/collections/17302408https://unsplash.com/collections/32603173https://unsplash.com/collections/64054584https://unsplash.com/collections/23587474https://unsplash.com/collections/19887216https://unsplash.com/collections/65119698https://unsplash.com/collections/84590463https://unsplash.com/collections/69491127https://unsplash.com/collections/58495416https://unsplash.com/collections/88700171https://unsplash.com/collections/86180540https://unsplash.com/collections/23165855https://unsplash.com/collections/66739827https://unsplash.com/collections/14226005https://unsplash.com/collections/20505512https://unsplash.com/collections/47255887https://unsplash.com/collections/60391212https://unsplash.com/collections/32740261https://unsplash.com/collections/33488053https://unsplash.com/collections/63526139https://unsplash.com/collections/29561812https://unsplash.com/collections/13051353https://unsplash.com/collections/46016418https://unsplash.com/collections/73632864https://unsplash.com/collections/44207615https://unsplash.com/collections/32673535https://unsplash.com/collections/24083059https://unsplash.com/collections/52116501https://unsplash.com/collections/75667030https://unsplash.com/collections/87794902https://unsplash.com/collections/34709071https://unsplash.com/collections/23358019https://unsplash.com/collections/91950586https://unsplash.com/collections/44556467https://unsplash.com/collections/76879031https://unsplash.com/collections/22076476https://unsplash.com/collections/30540195https://unsplash.com/collections/30929491https://unsplash.com/collections/66250828https://unsplash.com/collections/27531342https://unsplash.com/collections/81084085https://unsplash.com/collections/18912340https://unsplash.com/collections/44254650https://unsplash.com/collections/36075602https://unsplash.com/collections/35099291https://unsplash.com/collections/46400089https://unsplash.com/collections/89487216https://unsplash.com/collections/49839960https://unsplash.com/collections/56593163https://unsplash.com/collections/74011843https://unsplash.com/collections/44461015https://unsplash.com/collections/74711085https://unsplash.com/collections/82139504https://unsplash.com/collections/71675086https://unsplash.com/collections/69242865https://unsplash.com/collections/82728697https://unsplash.com/collections/17074322https://unsplash.com/collections/78745037https://unsplash.com/collections/24045490https://unsplash.com/collections/32815736https://unsplash.com/collections/83386179https://unsplash.com/collections/59707987https://unsplash.com/collections/97802480https://unsplash.com/collections/95927573https://unsplash.com/collections/31199515https://unsplash.com/collections/26044089https://unsplash.com/collections/86397710https://unsplash.com/collections/27249072https://unsplash.com/collections/76844237https://unsplash.com/collections/98186641https://unsplash.com/collections/78473382https://unsplash.com/collections/46331654https://unsplash.com/collections/53122617https://unsplash.com/collections/64321612https://unsplash.com/collections/57131987https://unsplash.com/collections/42479442https://unsplash.com/collections/44309603https://unsplash.com/collections/96000566https://unsplash.com/collections/20105760https://unsplash.com/collections/27832820https://unsplash.com/collections/22693623https://unsplash.com/collections/56559607https://unsplash.com/collections/31520502https://unsplash.com/collections/47512491https://unsplash.com/collections/88730286https://unsplash.com/collections/79330458https://unsplash.com/collections/72129264https://unsplash.com/collections/89315730https://unsplash.com/collections/62789791https://unsplash.com/collections/58994052https://unsplash.com/collections/21986170https://unsplash.com/collections/31712770https://unsplash.com/collections/45649987https://unsplash.com/collections/25707724https://unsplash.com/collections/65601102https://unsplash.com/collections/98622266https://unsplash.com/collections/36715968https://unsplash.com/collections/24397265https://unsplash.com/collections/68146579https://unsplash.com/collections/57848908https://unsplash.com/collections/14079273https://unsplash.com/collections/65862073https://unsplash.com/collections/88551358https://unsplash.com/collections/32716035https://unsplash.com/collections/49763945https://unsplash.com/collections/31153728https://unsplash.com/collections/70288324https://unsplash.com/collections/73165386https://unsplash.com/collections/13602678https://unsplash.com/collections/84585602https://unsplash.com/collections/56085486https://unsplash.com/collections/95936405https://unsplash.com/collections/69139195https://unsplash.com/collections/73570638https://unsplash.com/collections/42104263https://unsplash.com/collections/59127597https://unsplash.com/collections/89962091https://unsplash.com/collections/94825125https://unsplash.com/collections/72258434https://unsplash.com/collections/21707622https://unsplash.com/collections/47868367https://unsplash.com/collections/65239494https://unsplash.com/collections/15926033https://unsplash.com/collections/44101171https://unsplash.com/collections/20429464https://unsplash.com/collections/71811999https://unsplash.com/collections/48249221https://unsplash.com/collections/76459764https://unsplash.com/collections/46601472https://unsplash.com/collections/19858926https://unsplash.com/collections/46488075https://unsplash.com/collections/27298039https://unsplash.com/collections/68107777https://unsplash.com/collections/53367246https://unsplash.com/collections/28418802https://unsplash.com/collections/76799350https://unsplash.com/collections/77101938https://unsplash.com/collections/94101343https://unsplash.com/collections/13494295https://unsplash.com/collections/86835118https://unsplash.com/collections/90399406https://unsplash.com/collections/90134993https://unsplash.com/collections/33085624https://unsplash.com/collections/82195165https://unsplash.com/collections/83282684https://unsplash.com/collections/33157641https://unsplash.com/collections/94741815https://unsplash.com/collections/19548029https://unsplash.com/collections/78337088https://unsplash.com/collections/30354718https://unsplash.com/collections/90423626https://unsplash.com/collections/38049687https://unsplash.com/collections/73574955https://unsplash.com/collections/33231964https://unsplash.com/collections/72356984https://unsplash.com/collections/31256935https://unsplash.com/collections/70171433https://unsplash.com/collections/63930010https://unsplash.com/collections/29005092https://unsplash.com/collections/88543771https://unsplash.com/collections/57026082https://unsplash.com/collections/79323903https://unsplash.com/collections/17411213https://unsplash.com/collections/17032338https://unsplash.com/collections/68748806https://unsplash.com/collections/52342559https://unsplash.com/collections/50903687https://unsplash.com/collections/99667924https://unsplash.com/collections/47739311https://unsplash.com/collections/70855935https://unsplash.com/collections/48155539https://unsplash.com/collections/94543747https://unsplash.com/collections/93268453https://unsplash.com/collections/40445934https://unsplash.com/collections/44648616https://unsplash.com/collections/81021185https://unsplash.com/collections/99790533https://unsplash.com/collections/26053963https://unsplash.com/collections/90422671https://unsplash.com/collections/28494115https://unsplash.com/collections/92098008https://unsplash.com/collections/45224189https://unsplash.com/collections/93542444https://unsplash.com/collections/48046272https://unsplash.com/collections/85566735https://unsplash.com/collections/68918438https://unsplash.com/collections/61030874https://unsplash.com/collections/66146239https://unsplash.com/collections/78398945https://unsplash.com/collections/15432256https://unsplash.com/collections/90706308https://unsplash.com/collections/33391053https://unsplash.com/collections/25233246https://unsplash.com/collections/36047099https://unsplash.com/collections/14946935https://unsplash.com/collections/20929092https://unsplash.com/collections/98461617https://unsplash.com/collections/85362553https://unsplash.com/collections/17943592https://unsplash.com/collections/14945132https://unsplash.com/collections/38846221https://unsplash.com/collections/91421852https://unsplash.com/collections/82845238https://unsplash.com/collections/29075761https://unsplash.com/collections/86066356https://unsplash.com/collections/19040647https://unsplash.com/collections/96864148https://unsplash.com/collections/94438360https://unsplash.com/collections/64319373https://unsplash.com/collections/76847560https://unsplash.com/collections/85741105https://unsplash.com/collections/79504115https://unsplash.com/collections/33527786https://unsplash.com/collections/33253216https://unsplash.com/collections/47691295https://unsplash.com/collections/94842508https://unsplash.com/collections/45468024https://unsplash.com/collections/45756196https://unsplash.com/collections/81321780https://unsplash.com/collections/41534358https://unsplash.com/collections/51599676https://unsplash.com/collections/54899624https://unsplash.com/collections/14110594https://unsplash.com/collections/81748377https://unsplash.com/collections/69851992https://unsplash.com/collections/23360450https://unsplash.com/collections/73708697https://unsplash.com/collections/76829370https://unsplash.com/collections/21943818https://unsplash.com/collections/54443358https://unsplash.com/collections/45363289https://unsplash.com/collections/31878592https://unsplash.com/collections/49786166https://unsplash.com/collections/68929177https://unsplash.com/collections/49294104https://unsplash.com/collections/74226966https://unsplash.com/collections/76857973https://unsplash.com/collections/81154498https://unsplash.com/collections/17371748https://unsplash.com/collections/85056456https://unsplash.com/collections/81211189https://unsplash.com/collections/68452203https://unsplash.com/collections/30493312https://unsplash.com/collections/46026581https://unsplash.com/collections/69259072https://unsplash.com/collections/93223757https://unsplash.com/collections/32267200https://unsplash.com/collections/98842630https://unsplash.com/collections/39557063https://unsplash.com/collections/33163061https://unsplash.com/collections/36798303https://unsplash.com/collections/22429888https://unsplash.com/collections/42347354https://unsplash.com/collections/75956356


  docker exec -it mongo mongo admin
 ​
 # 创建一个名为 admin,密码为 123456 的用户。
 ​
 db.createUser({ user:'admin',pwd:'123456',roles:[ { role:'userAdminAnyDatabase', db: 'admin'},"readWriteAnyDatabase"]});
 ​
 # 尝试使用上面创建的用户信息进行连接。
 ​
 db.auth('admin', '123456')
 使用这个账号连接navicat是可以正常使用的,但是连接java代码会报错
 ​
 org.springframework.data.mongodb.UncategorizedMongoDbException:
  Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='admin', source='cloud_iexe', password=<hidden>, mechanismProperties=<hidden>}; nested exception is com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='admin', source='cloud_iexe', password=<hidden>, mechanismProperties=<hidden>}
 ​

于是我们百度了一下: -->创建新用户


 db.createUser(
      {
        user: "wenqiang",
        pwd: "1438438",
        roles: ["readWrite"]
      }
 )

使用新用户进行登录并测试插入代码


 @Document(collection = "user")
 public class MongoUser implements Serializable {
     @Id
     private String id;
 ​
     @Field("user_name")
     private String userName=null;
 ​
     private String note=null;
 ​
     @Field("roles")
     private List<MongoRole> roleList=null;
 ​
     public String getId() {
         return id;
    }
 ​
     public void setId(String id) {
         this.id = id;
    }
 ​
     public String getUserName() {
         return userName;
    }
 ​
     public void setUserName(String userName) {
         this.userName = userName;
    }
 ​
     public String getNote() {
         return note;
    }
 ​
     public void setNote(String note) {
         this.note = note;
    }
 ​
     public List<MongoRole> getRoleList() {
         return roleList;
    }
 ​
     public void setRoleList(List<MongoRole> roleList) {
         this.roleList = roleList;
    }
 }
 ​

db: 可以用通过template也可以用:


 public interface MongoDbUserRepository extends MongoRepository<MongoUser,String> {
 }
 ​
     public MongoUser saveUser(MongoUser mongoUser){
         MongoUser mongoUser1=mongoDbUserRepository.save(mongoUser);
         return mongoUser1;
    }

 


  @Autowired
     private MongoUserServiceImpl mongoUserService;
 ​
     @Test
     public void saveMongoUser(){
         MongoUser mongoUser=new MongoUser();
         mongoUser.setId("1");
         mongoUser.setUserName("亚索");
         mongoUser.setNote("托儿索");
         MongoRole mongoRole=new MongoRole();
         mongoRole.setId("3");
         mongoRole.setRoleName("中单");
         mongoRole.setNote("快乐风男");
         List<MongoRole> mongoRoleList=new ArrayList<MongoRole>();
         mongoRoleList.add(mongoRole);
         mongoUser.setRoleList(mongoRoleList);
         logger.info("新增用户{}",new Gson().toJson(mongoUserService.saveUser(mongoUser)));
    }

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_24219625/article/details/112761000

随机推荐

并发编程—synchronized 关键字 隐式锁

在上一篇中我们讲解了管程的概念,在Java中有两种实现管程的方式,分别是synchronized关键字和Lock接口,那么今天我们就先讲讲synchroniz...

猿博园 阅读(207)

乌班图的操作(1)

乌班图的操作1如果在很多的目录下,返会家目录的时候直接按cd或者cd~都是返回家目录的。在这里插入图片描述2.何进入到管理员用户先进入到用户模式,命令sudosu进入到用户...

看着你的背影 阅读(403)

Vue-json-viewer 展示JSON格式数据

最近在开发一个公司的投放管理系统的操作日志模块,要查看某条操作日志的请求参数,要将请求的参数以JSON格式的形式展示出来,于是用到了vue-json-view...

aiguangyuan 阅读(999)

Centos安装字体

1、查看中文字体fc-list:lang=zh2、安装字体yum-yinstallfontconfig#安装字体库yum-yinstallttmkfdirmkfontscale#安装字体索引信...

互联网-小阿宇 阅读(106)

力扣题解

第十二题题目43.字符串相乘给定两个以字符串形式表示的非负整数num1和num2,返回num1和num2的乘积,它们的乘积也表示为字符串形式。示例1:输入:num1=...

陈陈陈陈陈呀 阅读(960)

Android Jetpack详解

https://juejin.cn/post/6844903889574051848#heading-5...

星月黎明 阅读(479)

JAVA从头开始--API

APIAPI(ApplicationProgrammingInterface)应用程序编程接口。API是Java语言中提供的众多的类和接口也是官方对提供的类,接口的功能进行说明的文档。基...

crraxx 阅读(209)

Python数据类型&运算符

变量&Python数据类型&运算符一、变量1.变量1.1.概念定义:程序在运行的过程中,值可以随时发生改变作用:存储数据,参与运算1.2.定义定义格式...

世界上的程序员之一 阅读(579)