锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久久久se色偷偷亚洲精品av,亚洲一级黄色视频,亚洲一区二区三区免费http://m.tkk7.com/paulwong/category/53872.htmlzh-cnWed, 19 Oct 2022 02:40:02 GMTWed, 19 Oct 2022 02:40:02 GMT60MONGODB SPRING DISTINCThttp://m.tkk7.com/paulwong/archive/2022/10/18/450835.htmlpaulwongpaulwongTue, 18 Oct 2022 02:22:00 GMThttp://m.tkk7.com/paulwong/archive/2022/10/18/450835.htmlhttp://m.tkk7.com/paulwong/comments/450835.htmlhttp://m.tkk7.com/paulwong/archive/2022/10/18/450835.html#Feedback0http://m.tkk7.com/paulwong/comments/commentRss/450835.htmlhttp://m.tkk7.com/paulwong/services/trackbacks/450835.html
    private boolean needReorderCheck(String requestId) {
        boolean result = false;
//        try(MongoCursor<String> mongoCursor = 
//                mongoTemplate.getCollection(mongoTemplate.getCollectionName(AccountNumProductLineIndex.class))
//                             .distinct(KEY, Filters.eq(REQUEST_ID, requestId), String.class)
//                             .iterator()
//                )
        try(MongoCursor<Document> mongoCursor = 
                mongoTemplate.getCollection(mongoTemplate.getCollectionName(AccountNumProductLineIndex.class))
                             .aggregate(
                                 Arrays.asList(
                                    Aggregates.project(
                                                    Projections.fields(
                                                                    Projections.excludeId(),
                                                                   Projections.include(KEY),
                                                                   Projections.include(REQUEST_ID)
                                                                )
                                               ),
                                    Aggregates.match(Filters.eq(REQUEST_ID, requestId)),
                                    Aggregates.group("$" + KEY)
                                 )
                              )
                             .allowDiskUse(true)
                             .iterator();
        )
        {
            String key = null;
            boolean breakMe = false;
            LOGGER.info("needReorderCheck.key --> start");
            while(mongoCursor.hasNext()) {
                if(breakMe) {
                    mongoCursor.close();
                    break;
                }
                Document keyDocument = mongoCursor.next();
                key = keyDocument.getString("_id");
//                key = mongoCursor.next().getString(KEY);
//                LOGGER.info("needReorderCheck.keyDocument --> {}, key --> {}", keyDocument, key);
                try(MongoCursor<Document> indexMongoCursor = 
                        mongoTemplate.getCollection(AccountNumProductLineIndex.COLLECTION_NAME)
                                        .find(Filters.and(Filters.eq(REQUEST_ID, requestId), Filters.eq(KEY, key)))
                                        .iterator()
                )
                {
                    int preIndex = -1, currentIndex = -1;
                    Document preIndexDocument = null, currentIndexDocument;
                    while(indexMongoCursor.hasNext()) {
                        currentIndexDocument = indexMongoCursor.next();
//                        System.out.println(currentIndexDocument.toJson());
                        if(preIndexDocument != null) {
                             currentIndex = currentIndexDocument.getInteger(INDEX);
                             preIndex = preIndexDocument.getInteger(INDEX);
                             if(currentIndex - preIndex > 1) {
                                indexMongoCursor.close();
                                breakMe = true;
                                result = true;
                                break;
                            }
                        }
                        preIndexDocument = currentIndexDocument;
                    }
                }
            }
        }
        
        return result;
    }



paulwong 2022-10-18 10:22 鍙戣〃璇勮
]]>
MONGODB SHELLhttp://m.tkk7.com/paulwong/archive/2022/01/10/438649.htmlpaulwongpaulwongMon, 10 Jan 2022 03:10:00 GMThttp://m.tkk7.com/paulwong/archive/2022/01/10/438649.htmlhttp://m.tkk7.com/paulwong/comments/438649.htmlhttp://m.tkk7.com/paulwong/archive/2022/01/10/438649.html#Feedback0http://m.tkk7.com/paulwong/comments/commentRss/438649.htmlhttp://m.tkk7.com/paulwong/services/trackbacks/438649.htmlmongo -u admin -p 123456 --authenticationDatabase admin
use admin
db.createUser({
 user : "paul",
 pwd : "123456",
 roles : [{role : "readWrite", db : "batch"}]
})

#澧炲姞鏉冮檺
db.grantRolesToUser( 
  "paul"
  [
    { "role" : "dbOwner",
      "db" : "mcra"
    }
  ]
)

paulwong 2022-01-10 11:10 鍙戣〃璇勮
]]>
WEBFLUX + SPRING SESSION + REACTIVE MONGODBhttp://m.tkk7.com/paulwong/archive/2021/12/22/436240.htmlpaulwongpaulwongWed, 22 Dec 2021 01:24:00 GMThttp://m.tkk7.com/paulwong/archive/2021/12/22/436240.htmlhttp://m.tkk7.com/paulwong/comments/436240.htmlhttp://m.tkk7.com/paulwong/archive/2021/12/22/436240.html#Feedback0http://m.tkk7.com/paulwong/comments/commentRss/436240.htmlhttp://m.tkk7.com/paulwong/services/trackbacks/436240.html 娣誨姞渚濊禆錛宲om.xml
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
        
        
<!-- spring session with mongodb -->
<dependency>
   <groupId>org.springframework.session</groupId>
   <artifactId>spring-session-data-mongodb</artifactId>
</dependency>
        
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
</dependency>

閰嶇疆鏂囦歡錛宎pplication.yaml

spring:
   session:
      store-type: mongodb
      timeout: 30s
      mongodb:
         collection-name: WEB_SESSIONS


java閰嶇疆錛孒ttpSessionConfiguration.java錛?/h2>
package com.paul.testmicroservicecommon.config;

import org.springframework.boot.autoconfigure.session.MongoSessionProperties;
import org.springframework.boot.autoconfigure.session.SessionProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.session.config.ReactiveSessionRepositoryCustomizer;
import org.springframework.session.data.mongo.ReactiveMongoSessionRepository;
import org.springframework.session.data.mongo.config.annotation.web.reactive.EnableMongoWebSession;

@EnableMongoWebSession
@EnableConfigurationProperties(MongoSessionProperties.class)
public class HttpSessionConfiguration {
    
    @Bean
    public ReactiveSessionRepositoryCustomizer<ReactiveMongoSessionRepository> customize(
        SessionProperties sessionProperties,
        MongoSessionProperties mongoSessionProperties
    ){
        return c -> {
            c.setMaxInactiveIntervalInSeconds((int)sessionProperties.getTimeout().getSeconds());
            c.setCollectionName(mongoSessionProperties.getCollectionName());
        };
    }

}



paulwong 2021-12-22 09:24 鍙戣〃璇勮
]]>MONGODB鑱氬悎璧勬簮http://m.tkk7.com/paulwong/archive/2021/04/08/435847.htmlpaulwongpaulwongThu, 08 Apr 2021 05:38:00 GMThttp://m.tkk7.com/paulwong/archive/2021/04/08/435847.htmlhttp://m.tkk7.com/paulwong/comments/435847.htmlhttp://m.tkk7.com/paulwong/archive/2021/04/08/435847.html#Feedback0http://m.tkk7.com/paulwong/comments/commentRss/435847.htmlhttp://m.tkk7.com/paulwong/services/trackbacks/435847.htmlhttps://www.javaprogramto.com/2020/05/spring-boot-data-mongodb-projections-aggregations.html

In spring data mongodb how to achieve pagination for aggregation
https://stackoverflow.com/questions/34427241/in-spring-data-mongodb-how-to-achieve-pagination-for-aggregation

Create a ProjectionOperation with Difference with spring mongodb
https://stackoverflow.com/questions/46786577/create-a-projectionoperation-with-difference-with-spring-mongodb


paulwong 2021-04-08 13:38 鍙戣〃璇勮
]]>
SPRING DATA MONGODB 鏁欑▼http://m.tkk7.com/paulwong/archive/2020/11/20/435729.htmlpaulwongpaulwongFri, 20 Nov 2020 06:45:00 GMThttp://m.tkk7.com/paulwong/archive/2020/11/20/435729.htmlhttp://m.tkk7.com/paulwong/comments/435729.htmlhttp://m.tkk7.com/paulwong/archive/2020/11/20/435729.html#Feedback0http://m.tkk7.com/paulwong/comments/commentRss/435729.htmlhttp://m.tkk7.com/paulwong/services/trackbacks/435729.htmlhttps://github.com/eugenp/tutorials/tree/master/persistence-modules/spring-data-mongodb


paulwong 2020-11-20 14:45 鍙戣〃璇勮
]]>
Finding slow queries in MongoDBhttp://m.tkk7.com/paulwong/archive/2020/03/27/435309.htmlpaulwongpaulwongFri, 27 Mar 2020 15:35:00 GMThttp://m.tkk7.com/paulwong/archive/2020/03/27/435309.htmlhttp://m.tkk7.com/paulwong/comments/435309.htmlhttp://m.tkk7.com/paulwong/archive/2020/03/27/435309.html#Feedback0http://m.tkk7.com/paulwong/comments/commentRss/435309.htmlhttp://m.tkk7.com/paulwong/services/trackbacks/435309.htmlDatabase Profiling

MongoDB Profiler is a db profiling system that can help identify inefficient

or slow queries and operations.

Levels of profiles available are:

Level

Setting

0

Off. & No profiling

1

On & only includes slow operations

2

On & Includes all operations


We can enable it by setting the Profile level value using the following
command in mongo shell :

"db.setProfilingLevel(1)"

By default, mongod records slow queries to its log, as defined by slowOpThresholdMs.

NOTE

Enabling database profiler puts negative impact on MongoDB’s performance.

It’s better to enable it for specific intervals & minimal on Production Servers.

We can enable profiling on a mongod basis but This setting will not propagate
across a replica set and sharded cluster.

We can view the output in the system.profile collection in mongo shell using show profile command, or using following:

db.system.profile.find( { millis : { $gt : 200 } } )

Command returns operations that took longer than 200 ms. Similarly we
can change the values as per our need.

Enabling profile for an entire mongod instance.

For the purpose of development in testing, we can enable database profiling/settings for an 
entire mongod instance. The profiling level will be applied to all databases.

 

NOTE:

We can't enable the profiling settings on a mongos instance. To enable the profiling in

shard clusters, we have to enable/start profiling for each mongod instance in cluster.

 

Query for the recent 10 entries

db.system.profile.find().limit(10).sort( { ts : 1 } ).pretty()

 

Collection with the slowest queries(No. Of queries)

db.system.profile.group({key: {ns: true}, initial: {count: 0}, reduce: function(obj,prev){ prev.count++;}})

 

Collection with the slowest queries(No. Of millis spent)

db.system.profile.group({key: {ns: true}, initial: {millis: 0}, reduce: function(obj, prev){ prev.millis += obj.millis;}})

 

Most recent slow query

db.system.profile.find().sort({$natural: -1}).limit(1)

 

Single slowest query(Right now)

db.system.profile.find().sort({millis: -1}).limit(1)



paulwong 2020-03-27 23:35 鍙戣〃璇勮
]]>
Spring Boot Data Mongodb Starter鑷姩閰嶇疆閭d簺鍧?/title><link>http://m.tkk7.com/paulwong/archive/2020/03/17/435271.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Tue, 17 Mar 2020 01:39:00 GMT</pubDate><guid>http://m.tkk7.com/paulwong/archive/2020/03/17/435271.html</guid><wfw:comment>http://m.tkk7.com/paulwong/comments/435271.html</wfw:comment><comments>http://m.tkk7.com/paulwong/archive/2020/03/17/435271.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/paulwong/comments/commentRss/435271.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/paulwong/services/trackbacks/435271.html</trackback:ping><description><![CDATA[<div style="font-size: medium;"><div><p>姝eソ鍋歁ongodb涓諱粠澶嶅埗灝濊瘯浣跨敤Spring Boot Data Mongodb Starter鎻掍歡閾炬帴璁塊棶Mongodb鏁版嵁搴撻泦緹ゃ?/p><p>閬囧埌鐨勫潙錛?/p><ul><li>spring.data.mongodb.host鍜宻pring.data.mongodb.port褰㈠紡涓嶉傚悎闆嗙兢閰嶇疆錛屼細(xì)鎶ost鏃犳硶璇嗗埆寮傚父</li><li>spring.data.mongodb.uri涓粡甯告姏鍑篴uthentication failed寮傚父</li></ul><p><br /></p><p>瑙e喅鍔炴硶錛?/p><ol><li> 瀵逛簬絎竴涓潙錛岃浣跨敤spring.data.mongodb.uri銆?span style="background-color: yellow;">濡傛灉浣跨敤浜唘ri錛屽垯鍏朵綑鐨刪ost/username/password/db/auth-db榪欎簺鍏ㄩ儴鏃犳晥銆?/span></li><li> 瀵逛簬絎簩涓潙錛岃鍦╯pring.data.mongodb.uri涓寚瀹歳eplicaSet鍜宎uthsource錛屽彟澶栬寰楁妸鎵鏈夐泦緹よ妭鐐規(guī)湇鍔″櫒鍦板潃閮藉垪鍏ㄣ?br /><span style="background-color: yellow;">濡傛灉auth-db鍜宒b鏄悓涓涓紝鍒欐棤闇鍔燼uthsource錛屽鏋滀笉鍚岋紝鍒欏姞authsource=admin</span></li></ol><p><br /></p><p>鎴戞病鏈夋妸authsource鎸囧畾錛屾墍浠ヤ竴鐩存姤authentication failed寮傚父銆傜劧鍚庡彧濂戒竴鐐圭偣鍘誨彂鎺橀棶棰樼偣錛屾渶鍚庢煡鍒板湪com.mongodb.ConnectionString綾諱腑鐨刢reateCredentials涓?br /><br /></p><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; ">private</span> MongoCredential createCredentials(<span style="color: #0000FF; ">final</span> Map<String, List<String>> optionsMap, <span style="color: #0000FF; ">final</span> String userName,<br />                                              <span style="color: #0000FF; ">final</span> <span style="color: #0000FF; ">char</span>[] password) {<br />        AuthenticationMechanism mechanism = <span style="color: #0000FF; ">null</span>;<br />        String authSource = (database == <span style="color: #0000FF; ">null</span>) ? "admin" : database;<br />        String gssapiServiceName = <span style="color: #0000FF; ">null</span>;<br />        String authMechanismProperties = <span style="color: #0000FF; ">null</span>;<br /><br />        <span style="color: #0000FF; ">for</span> (<span style="color: #0000FF; ">final</span> String key : AUTH_KEYS) {<br />            String value = getLastValue(optionsMap, key);<br /><br />            <span style="color: #0000FF; ">if</span> (value == <span style="color: #0000FF; ">null</span>) {<br />                <span style="color: #0000FF; ">continue</span>;<br />            }<br /><br />            <span style="color: #0000FF; ">if</span> (key.equals("authmechanism")) {<br />                mechanism = AuthenticationMechanism.fromMechanismName(value);<br />            } <span style="color: #0000FF; ">else</span> <span style="color: #0000FF; ">if</span> (key.equals("authsource")) {<br />                authSource = value;<br />            } <span style="color: #0000FF; ">else</span> <span style="color: #0000FF; ">if</span> (key.equals("gssapiservicename")) {<br />                gssapiServiceName = value;<br />            } <span style="color: #0000FF; ">else</span> <span style="color: #0000FF; ">if</span> (key.equals("authmechanismproperties")) {<br />                authMechanismProperties = value;<br />            }<br />        }<br /><br /><br />        MongoCredential credential = <span style="color: #0000FF; ">null</span>;<br />        <span style="color: #0000FF; ">if</span> (mechanism != <span style="color: #0000FF; ">null</span>) {<br />            <span style="color: #0000FF; ">switch</span> (mechanism) {<br />                <span style="color: #0000FF; ">case</span> GSSAPI:<br />                    credential = MongoCredential.createGSSAPICredential(userName);<br />                    <span style="color: #0000FF; ">if</span> (gssapiServiceName != <span style="color: #0000FF; ">null</span>) {<br />                        credential = credential.withMechanismProperty("SERVICE_NAME", gssapiServiceName);<br />                    }<br />                    <span style="color: #0000FF; ">break</span>;<br />                <span style="color: #0000FF; ">case</span> PLAIN:<br />                    credential = MongoCredential.createPlainCredential(userName, authSource, password);<br />                    <span style="color: #0000FF; ">break</span>;<br />                <span style="color: #0000FF; ">case</span> MONGODB_CR:<br />                    credential = MongoCredential.createMongoCRCredential(userName, authSource, password);<br />                    <span style="color: #0000FF; ">break</span>;<br />                <span style="color: #0000FF; ">case</span> MONGODB_X509:<br />                    credential = MongoCredential.createMongoX509Credential(userName);<br />                    <span style="color: #0000FF; ">break</span>;<br />                <span style="color: #0000FF; ">case</span> SCRAM_SHA_1:<br />                    credential = MongoCredential.createScramSha1Credential(userName, authSource, password);<br />                    <span style="color: #0000FF; ">break</span>;<br />                <span style="color: #0000FF; ">default</span>:<br />                    <span style="color: #0000FF; ">throw</span> <span style="color: #0000FF; ">new</span> UnsupportedOperationException(format("The connection string contains an invalid authentication mechanism'. "<br />                                                                           + "'%s' is not a supported authentication mechanism",<br />                            mechanism));<br />            }<br />        } <span style="color: #0000FF; ">else</span> <span style="color: #0000FF; ">if</span> (userName != <span style="color: #0000FF; ">null</span>) {<br />            credential = MongoCredential.createCredential(userName, authSource, password);<br />        }<br /><br />        <span style="color: #0000FF; ">if</span> (credential != <span style="color: #0000FF; ">null</span> && authMechanismProperties != <span style="color: #0000FF; ">null</span>) {<br />            <span style="color: #0000FF; ">for</span> (String part : authMechanismProperties.split(",")) {<br />                String[] mechanismPropertyKeyValue = part.split(":");<br />                <span style="color: #0000FF; ">if</span> (mechanismPropertyKeyValue.length != 2) {<br />                    <span style="color: #0000FF; ">throw</span> <span style="color: #0000FF; ">new</span> IllegalArgumentException(format("The connection string contains invalid authentication properties. "<br />                            + "'%s' is not a key value pair", part));<br />                }<br />                String key = mechanismPropertyKeyValue[0].trim().toLowerCase();<br />                String value = mechanismPropertyKeyValue[1].trim();<br />                <span style="color: #0000FF; ">if</span> (key.equals("canonicalize_host_name")) {<br />                    credential = credential.withMechanismProperty(key, Boolean.valueOf(value));<br />                } <span style="color: #0000FF; ">else</span> {<br />                    credential = credential.withMechanismProperty(key, value);<br />                }<br />            }<br />        }<br />        <span style="color: #0000FF; ">return</span> credential;<br />    }</div><p><br /></p><p>authSource榛樿浼?xì)鎸囧悜鎴戜滑鐩爣鏁版嵁鐨勬暟鎹簱銆傜劧鑰屽湪韜喚楠岃瘉鏈哄埗涓垜浠氬父闇瑕佹寚鍚慳dmin銆傦紙闈炲父鎯蟲姤綺楀彛錛屼唬鐮佷綔鑰呭湪榪欓噷鑴戣琚玬en鎸や簡涔堬級銆傛墍浠ラ渶瑕佸己鍒舵寚瀹歛uthSource涓寚瀹氥傚叿浣撴寚瀹氭柟寮忓涓嬶細(xì)</p><p> </p><p> </p><p> </p><p> </p><pre bash"=""><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->mongodb://{鐢ㄦ埛鍚峿:{瀵嗙爜}@{host1}:27017,{host2}:27017,{host3}:27017/{鐩爣鏁版嵁搴搣?replicaSet={澶嶅埗闆嗗悕縐皚&write=1&readPreference=primary&authsource={鎺堟潈鏁版嵁搴搣</div></pre></div></div><img src ="http://m.tkk7.com/paulwong/aggbug/435271.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/paulwong/" target="_blank">paulwong</a> 2020-03-17 09:39 <a href="http://m.tkk7.com/paulwong/archive/2020/03/17/435271.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>MongDB榪炴帴姹犲弬鏁皊erverSelectionTimeout銆乧onnectTimeout銆乵axWaitTime鍜宻ocketTimeout浠嬬粛http://m.tkk7.com/paulwong/archive/2020/03/07/435231.htmlpaulwongpaulwongSat, 07 Mar 2020 12:58:00 GMThttp://m.tkk7.com/paulwong/archive/2020/03/07/435231.htmlhttp://m.tkk7.com/paulwong/comments/435231.htmlhttp://m.tkk7.com/paulwong/archive/2020/03/07/435231.html#Feedback0http://m.tkk7.com/paulwong/comments/commentRss/435231.htmlhttp://m.tkk7.com/paulwong/services/trackbacks/435231.htmlMongDB Client璇鋒眰鏌ヨ鏁版嵁錛岄渶瑕佸寘鎷簲涓樁孌碉細(xì)
MongoDB Client闇瑕佹壘鍒板彲鐢ㄧ殑MongoDB Server
MongoDB Client闇瑕佸拰MongoDB Server寤虹珛錛坣ew錛塁onnection
搴旂敤紼嬪簭澶勭悊綰跨▼浠嶤onnection Pool涓幏鍙朇onnection
鏁版嵁浼犺緭錛堣幏鍙栬繛鎺ュ悗錛岃繘琛孲ocket閫氫俊錛岃幏鍙栨暟鎹級
鏂紑Collection
閭d箞錛孧ongoDB Client椹卞姩璁劇疆涓綉緇滅浉鍏崇瓑寰呰秴鏃跺弬鏁皊erverSelectionTimeout銆乧onnectTimeout銆乵axWaitTime鍜宻ocketTimeout鍒嗗埆瀵瑰簲涓婇潰鍝釜鐜妭鍛紵
鍙傛暟serverSelectionTimeout錛氬搴旂1涓幆鑺傦紝鍗矼ongoDB Client闇瑕佹壘鍒板彲鐢ㄧ殑MongoDB Server鎵闇瑕佺殑絳夊緟鏃墮棿錛?nbsp;                                            MongDB閮ㄧ講鐨勭敓浜т竴鑸敱澶氫釜鏈嶅姟鍣ㄧ粍鎴愶紝瑕佷箞浣滀負(fù)涓涓鍒墮泦鎴栬呬綔涓轟竴涓垎鐗囬泦緹わ紝鍙傛暟                                                     serverSelectionTimeout鐨勫煎嵆涓哄闀挎椂闂村唴鎵句笉鍒板悎閫傛湇鍔″櫒鏃跺欏氨鍐沖畾鏀懼純鐨勬椂闂撮棿闅旓紱
鍙傛暟connectTimeout錛氬搴旂2涓幆鑺傦紝姣忔鍒涘緩Connection錛屽搴旂殑緗戠粶絳夊緟銆傚崟浣嶆縐掓暟, 0琛ㄧず娌℃湁闄愬埗錛?/div>
鍙傛暟maxWaitTime錛氬搴旂3涓幆鑺傦紝搴旂敤紼嬪簭澶勭悊綰跨▼浠庤繛鎺ユ睜涓幏鍙朇ollection錛屽搴旂殑緗戠粶絳夊緟鏃墮棿銆傚崟浣嶆縐掓暟錛?琛ㄧず                                   涓嶇瓑寰咃紝璐熸暟琛ㄧず絳夊緟鏃墮棿涓嶇‘瀹氾紱
鍙傛暟socketTimeout錛氬搴旂4涓幆鑺傦紝鑾峰彇Connection鍚庯紝灝辨湁浜哠ocket閫氫俊錛岃幏鍙栨暟鎹紝鍗沖湪MonogoDB Client                                                      鍜孧onogoDB Server鐨凷ocket閫氫俊榪囩▼涓殑緗戠粶絳夊緟鏃墮棿銆傚崟浣嶆縐掓暟錛岄粯璁ら厤緗負(fù)0錛屼篃灝辨槸娌℃湁闄愬埗錛?nbsp;                                 娌℃湁瓚?鏃墮檺鍒訛紝緋葷粺鍑轟簡闂涔熶笉瀹規(guī)槗鍙戠幇錛屽簲璇ユ牴鎹疄闄呮儏鍐碉紝緇欏嚭鍚堢悊鐨勮秴鏃舵椂闂淬?/div>
 
鍏朵粬鐩稿叧鍙傛暟濡備笅錛?/div>
connectionsPerHost錛氬mongo瀹炰緥鏉ヨ錛屾瘡涓猦ost鍏佽閾炬帴鐨勬渶澶ч摼鎺ユ暟,榪欎簺閾炬帴絀洪棽鏃朵細(xì)鏀懼叆姹犱腑,濡傛灉閾炬帴琚楀敖錛屼換浣曡姹傞摼鎺ョ殑鎿嶄綔浼?xì)琚樥d絳夊緟閾炬帴鍙敤,鎺ㄨ崘閰嶇疆10
minPoolsSize錛氬綋Connection絀洪棽鏃?Connection Pool涓渶灝慍onnection淇濇湁閲忥紱
threadsAllowedToBlockForConnectionMultiplier錛氭瘡涓狢onnection鐨勫彲浠ラ樆濉炵瓑寰呯殑綰跨▼闃熷垪鏁幫紝瀹冧互涓婇潰connectionsPerHost鍊肩浉涔樼殑緇撴灉灝辨槸闃誨絳夊緟鐨勭嚎紼嬮槦鍒楁渶澶у箋傚鏋滆繛鎺ョ嚎紼嬫帓婊′簡闃熷垪灝變細(xì)鎶涘嚭“Out of semaphores to get db”閿欒銆?/div>
socketKeepAlive:璇ユ爣蹇楃敤浜庢帶鍒秙ocket淇濇寔媧誨姩鐨勫姛鑳斤紝閫氳繃闃茬伀澧欎繚鎸佽繛鎺ユ椿鐫
socketKeepAlive=false
autoConnectRetry錛氳繖涓帶鍒舵槸鍚﹀湪涓涓狢onnection鏃訛紝緋葷粺浼?xì)鑷姩閲嶈?/div>
#true:鍋囧Connection涓嶈兘寤虹珛鏃?椹卞姩灝嗛噸璇曠浉鍚岀殑server,鏈夋渶澶х殑閲嶈瘯嬈℃暟,榛樿涓?5嬈?榪欐牱鍙互閬垮厤涓浜泂erver鍥犱負(fù)涓浜涢樆濉炴搷浣滈浂鏃禿own鑰岄┍鍔ㄦ姏鍑哄紓甯?榪欎釜瀵瑰鉤婊戣繃搴﹀埌涓涓柊鐨刴aster,涔熸槸寰堟湁鐢ㄧ殑,娉ㄦ剰:褰撻泦緹や負(fù)澶嶅埗闆嗘椂,椹卞姩灝嗗湪榪欐鏃墮棿閲?灝濊瘯閾炬帴鍒版棫鐨刴aster涓?鑰屼笉浼?xì)椹笂閾炬帴鍒版柊master涓?/div>
#false 褰撳湪榪涜socket璇誨啓鏃?涓嶄細(xì)闃繪寮傚父鎶涘嚭,椹卞姩宸茬粡鏈夎嚜鍔ㄩ噸寤虹牬鍧忛摼鎺ュ拰閲嶈瘯璇繪搷浣? 鎺ㄨ崘閰嶇疆false
autoConnectRetry=false
#閲嶆柊鎵撳紑閾炬帴鍒扮浉鍚宻erver鐨勬渶澶ф縐掓暟,鎺ㄨ崘閰嶇疆涓?錛屽鏋?autoConnectRetry=true,琛ㄧず鏃墮棿涓?5s
#com.jd.mongodbclient2.mongo.JDClientMongo.maxAutoConnectRetryTime=false
#琛ㄧず褰撴病鏈夋墜鍔ㄥ叧闂父鏍囨椂,鏄惁鏈変竴涓嚜鍔ㄩ噴鏀炬父鏍囧璞$殑鏂規(guī)硶,濡傛灉浣犳繪槸寰堝皬蹇冪殑鍏抽棴娓告爣,鍒欏彲浠ュ皢鍏惰涓篺alse 鎺ㄨ崘閰嶇疆true

https://docs.mongodb.com/manual/reference/connection-string/#connections-connection-options
————————————————
鐗堟潈澹版槑錛氭湰鏂囦負(fù)CSDN鍗氫富銆宲ursuer211銆嶇殑鍘熷垱鏂囩珷錛岄伒寰?CC 4.0 BY-SA 鐗堟潈鍗忚錛岃漿杞借闄勪笂鍘熸枃鍑哄閾炬帴鍙?qiáng)鏈0鏄庛?/div>
鍘熸枃閾炬帴錛歨ttps://blog.csdn.net/pursuer211/article/details/82994027


paulwong 2020-03-07 20:58 鍙戣〃璇勮
]]>Mongodb shell涓璼elect in 鐨勫疄鐜?/title><link>http://m.tkk7.com/paulwong/archive/2020/02/21/435146.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Fri, 21 Feb 2020 15:10:00 GMT</pubDate><guid>http://m.tkk7.com/paulwong/archive/2020/02/21/435146.html</guid><wfw:comment>http://m.tkk7.com/paulwong/comments/435146.html</wfw:comment><comments>http://m.tkk7.com/paulwong/archive/2020/02/21/435146.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/paulwong/comments/commentRss/435146.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/paulwong/services/trackbacks/435146.html</trackback:ping><description><![CDATA[<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->var bookIds = db.likes.find({userId:100}).map(function(like) { <br />  return like.bookId<span style="color: #008000; ">;</span><span style="color: #008000; "> </span><span style="color: #008000; "><br /></span>})<span style="color: #008000; ">;<br /></span>var books = db.books.find({_id:{$in:bookIds}})<span style="color: #008000; ">;</span></div><br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->db.REPORT_ITEM.count({REQUEST_ID : db.BATCH_CONTROL.find({ FILE_NAME : "20200218_100000.file" }).map(function(like) { <br />  return like._id<span style="color: #008000; ">;</span><span style="color: #008000; "> </span><span style="color: #008000; "><br /></span>})<span style="color: #800000; font-weight: bold; ">[</span><span style="color: #800000; ">0</span><span style="color: #800000; font-weight: bold; ">]</span>.str, JOB_TYPE_ENUM:"CHECK"})</div><img src ="http://m.tkk7.com/paulwong/aggbug/435146.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/paulwong/" target="_blank">paulwong</a> 2020-02-21 23:10 <a href="http://m.tkk7.com/paulwong/archive/2020/02/21/435146.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>mongodb閿欒璁板綍http://m.tkk7.com/paulwong/archive/2020/02/21/435142.htmlpaulwongpaulwongFri, 21 Feb 2020 00:50:00 GMThttp://m.tkk7.com/paulwong/archive/2020/02/21/435142.htmlhttp://m.tkk7.com/paulwong/comments/435142.htmlhttp://m.tkk7.com/paulwong/archive/2020/02/21/435142.html#Feedback0http://m.tkk7.com/paulwong/comments/commentRss/435142.htmlhttp://m.tkk7.com/paulwong/services/trackbacks/435142.htmlhttps://blog.csdn.net/wangxiaotongfan/article/details/81560463




paulwong 2020-02-21 08:50 鍙戣〃璇勮
]]>
MONGODB瀹夎http://m.tkk7.com/paulwong/archive/2019/11/15/434911.htmlpaulwongpaulwongFri, 15 Nov 2019 09:30:00 GMThttp://m.tkk7.com/paulwong/archive/2019/11/15/434911.htmlhttp://m.tkk7.com/paulwong/comments/434911.htmlhttp://m.tkk7.com/paulwong/archive/2019/11/15/434911.html#Feedback0http://m.tkk7.com/paulwong/comments/commentRss/434911.htmlhttp://m.tkk7.com/paulwong/services/trackbacks/434911.html https://www.jianshu.com/p/d3b31b7aa182 

鍚庣畫鍒濆鍖栫敤鎴峰強(qiáng)鏁版嵁搴?br />http://www.qianduan8.com/1786.html
https://zocada.com/setting-mongodb-users-beginners-guide/

濡傛灉瑕佷互璁よ瘉鐨勬柟寮忕櫥褰曪紝闇鍔犱互涓嬪唴瀹硅嚦/etc/mongod.conf
security:
  authorization: enabled

濡傛灉鐢℅UI榪炴帴鏁版嵁搴撴椂錛屼笉鏄劇ず鏁版嵁搴撳垪琛紝瑕佸姞鏉冮檺錛歭istDatabases
https://stackoverflow.com/questions/19458524/mongodb-show-dbs-and-show-log-without-clusteradmin-role



paulwong 2019-11-15 17:30 鍙戣〃璇勮
]]>
MONGODB鎷撳睍鎿嶄綔http://m.tkk7.com/paulwong/archive/2019/09/03/434556.htmlpaulwongpaulwongTue, 03 Sep 2019 07:52:00 GMThttp://m.tkk7.com/paulwong/archive/2019/09/03/434556.htmlhttp://m.tkk7.com/paulwong/comments/434556.htmlhttp://m.tkk7.com/paulwong/archive/2019/09/03/434556.html#Feedback0http://m.tkk7.com/paulwong/comments/commentRss/434556.htmlhttp://m.tkk7.com/paulwong/services/trackbacks/434556.htmlhttps://blog.csdn.net/ClementAD/article/details/55210973

Spring Data MongoDB緋誨垪涔嬩笁錛氭暟鎹簱鎵歸噺鎿嶄綔
https://blog.csdn.net/sinat_24044957/article/details/80646292

Distinct in Spring Data MongoDB
https://stackoverflow.com/questions/19203724/distinct-in-spring-data-mongodb

MONGODB銆SQL璇彞
http://www.runoob.com/mongodb/mongodb-indexing.html




paulwong 2019-09-03 15:52 鍙戣〃璇勮
]]>
Multiple MongoDB connectors with Spring Boothttp://m.tkk7.com/paulwong/archive/2019/06/20/433910.htmlpaulwongpaulwongThu, 20 Jun 2019 07:12:00 GMThttp://m.tkk7.com/paulwong/archive/2019/06/20/433910.htmlhttp://m.tkk7.com/paulwong/comments/433910.htmlhttp://m.tkk7.com/paulwong/archive/2019/06/20/433910.html#Feedback0http://m.tkk7.com/paulwong/comments/commentRss/433910.htmlhttp://m.tkk7.com/paulwong/services/trackbacks/433910.htmlhttp://blog.marcosbarbero.com/multiple-mongodb-connectors-in-spring-boot/

https://github.com/yinjihuan/spring-boot-starter-mongodb-pool

https://github.com/lish1le/mongodb-plus


paulwong 2019-06-20 15:12 鍙戣〃璇勮
]]>
SpringBoot浣跨敤MongoDB寮傚父闂http://m.tkk7.com/paulwong/archive/2019/05/29/433819.htmlpaulwongpaulwongWed, 29 May 2019 08:58:00 GMThttp://m.tkk7.com/paulwong/archive/2019/05/29/433819.htmlhttp://m.tkk7.com/paulwong/comments/433819.htmlhttp://m.tkk7.com/paulwong/archive/2019/05/29/433819.html#Feedback0http://m.tkk7.com/paulwong/comments/commentRss/433819.htmlhttp://m.tkk7.com/paulwong/services/trackbacks/433819.htmlhttps://www.cnblogs.com/linzhanfly/p/9674778.html

paulwong 2019-05-29 16:58 鍙戣〃璇勮
]]>
MONGODB鍘婚櫎_class瀛楁http://m.tkk7.com/paulwong/archive/2019/05/29/433818.htmlpaulwongpaulwongWed, 29 May 2019 06:18:00 GMThttp://m.tkk7.com/paulwong/archive/2019/05/29/433818.htmlhttp://m.tkk7.com/paulwong/comments/433818.htmlhttp://m.tkk7.com/paulwong/archive/2019/05/29/433818.html#Feedback0http://m.tkk7.com/paulwong/comments/commentRss/433818.htmlhttp://m.tkk7.com/paulwong/services/trackbacks/433818.html
MongodbConfiguration.java
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.MongoDbFactory;
import org.springframework.data.mongodb.core.convert.DbRefResolver;
import org.springframework.data.mongodb.core.convert.DefaultDbRefResolver;
import org.springframework.data.mongodb.core.convert.DefaultMongoTypeMapper;
import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
 
@Configuration
public class AppMongoConfig {
  @Autowired private MongoDbFactory mongoDbFactory;
 
  @Autowired private MongoMappingContext mongoMappingContext;
 
  @Bean
  public MappingMongoConverter mappingMongoConverter() {
 
    DbRefResolver dbRefResolver = new DefaultDbRefResolver(mongoDbFactory);
    MappingMongoConverter converter = new MappingMongoConverter(dbRefResolver, mongoMappingContext);
    converter.setTypeMapper(new DefaultMongoTypeMapper(null));
 
    return converter;
  }
}


paulwong 2019-05-29 14:18 鍙戣〃璇勮
]]>
MongoDB鍋ュ.闆嗙兢鈥斺旂敤鍓湰闆嗗仛鍒嗙墖http://m.tkk7.com/paulwong/archive/2015/12/18/428724.htmlpaulwongpaulwongFri, 18 Dec 2015 06:03:00 GMThttp://m.tkk7.com/paulwong/archive/2015/12/18/428724.htmlhttp://m.tkk7.com/paulwong/comments/428724.htmlhttp://m.tkk7.com/paulwong/archive/2015/12/18/428724.html#Feedback0http://m.tkk7.com/paulwong/comments/commentRss/428724.htmlhttp://m.tkk7.com/paulwong/services/trackbacks/428724.html闃呰鍏ㄦ枃

paulwong 2015-12-18 14:03 鍙戣〃璇勮
]]>
鍒╃敤Mongodb鐨勫鍒墮泦鎼緩楂樺彲鐢ㄥ垎鐗囷紝Replica Sets + Sharding鐨勬惌寤鴻繃紼?/title><link>http://m.tkk7.com/paulwong/archive/2015/12/18/428723.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Fri, 18 Dec 2015 05:54:00 GMT</pubDate><guid>http://m.tkk7.com/paulwong/archive/2015/12/18/428723.html</guid><wfw:comment>http://m.tkk7.com/paulwong/comments/428723.html</wfw:comment><comments>http://m.tkk7.com/paulwong/archive/2015/12/18/428723.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/paulwong/comments/commentRss/428723.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/paulwong/services/trackbacks/428723.html</trackback:ping><description><![CDATA[     鎽樿: 鍙傝冭祫鏂?nbsp;reference:  http://mongodb.blog.51cto.com/1071559/740131  http://docs.mongodb.org/manual/tutorial/deploy-shard-cluster/#sharding-setup-shard-collection鎰熻阿緗戝弸Mr.Sharp錛屼粬緇欎簡鎴戝緢澶?..  <a href='http://m.tkk7.com/paulwong/archive/2015/12/18/428723.html'>闃呰鍏ㄦ枃</a><img src ="http://m.tkk7.com/paulwong/aggbug/428723.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/paulwong/" target="_blank">paulwong</a> 2015-12-18 13:54 <a href="http://m.tkk7.com/paulwong/archive/2015/12/18/428723.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>MONGODB鐨勫鍒朵笌鍒嗙墖http://m.tkk7.com/paulwong/archive/2015/12/18/428720.htmlpaulwongpaulwongFri, 18 Dec 2015 05:21:00 GMThttp://m.tkk7.com/paulwong/archive/2015/12/18/428720.htmlhttp://m.tkk7.com/paulwong/comments/428720.htmlhttp://m.tkk7.com/paulwong/archive/2015/12/18/428720.html#Feedback0http://m.tkk7.com/paulwong/comments/commentRss/428720.htmlhttp://m.tkk7.com/paulwong/services/trackbacks/428720.html
  • 涓鑸富浠庯細(xì)涓涓誨浠庯紝涓諱綔璇誨啓鏁版嵁錛屼粠浣滀粠涓誨浠芥暟鎹敤錛屽鏋滀富瀹曟満錛屽垯鏁翠釜MONGODB鏃犳硶宸ヤ綔銆?/li>
  • 澶嶅埗寮忎富浠庯細(xì)涓鍔ㄦ佷富澶氫粠錛屼富鐢遍変婦浜х敓錛屽綋涓竴涓富瀹曟満錛屽叾浠栫殑浠庝細(xì)閫夊嚭涓涓富銆?/li>

閫傜敤鍦烘櫙錛氶珮璐熻嵎鐨勮澶氬啓灝戙?br />
鍒嗙墖錛歋HARDING錛屼竴鑸暟鎹簱涓殑鍒嗗簱鍒嗚〃錛屼竴涓〃鍒嗘垚鍑犱釜琛ㄧ敤銆傛瘡涓墖鍐嶅仛澶嶅埗銆?br />
閫傜敤鍦烘櫙錛氶珮璐熻嵎鐨勫啓澶氳灝戙傚嵆濡傛灉鍙戠幇MONGODB鍐欎笉鑳芥敮鎾戜簡錛屽垯瑕佽漿姝ゆā寮忋?br />
瀹夎閰嶇疆鏈嶅姟鍣紝瀹夎ROUTER錛歁ONGOS錛屽畨瑁呭垎鐗囨湇鍔″櫒錛岄氱煡MONGOS鎸傝澆SHARD銆?br />
濡傛灉鍙惎鐢ㄦ暟鎹簱鐨勫垎鐗囷紝鍒欎笉鍚岀殑琛ㄦ斁鍦ㄤ笉鍚岀殑鍒嗙墖涓婏紝鍗充竴涓〃鍙崰涓涓垎鐗囷紝鍙︿竴涓〃鍗犲彟涓涓垎鐗囷紝濡傛灉鍋氫簡琛ㄧ殑鍒嗙墖錛屽垯姝よ〃浼?xì)鍒嗗竷鍦ㄦ墍鏈夊垎鐗囦笂銆?br />












paulwong 2015-12-18 13:21 鍙戣〃璇勮
]]>
mongodb鐨勭洃鎺т笌鎬ц兘浼樺寲http://m.tkk7.com/paulwong/archive/2015/12/16/428691.htmlpaulwongpaulwongWed, 16 Dec 2015 10:50:00 GMThttp://m.tkk7.com/paulwong/archive/2015/12/16/428691.htmlhttp://m.tkk7.com/paulwong/comments/428691.htmlhttp://m.tkk7.com/paulwong/archive/2015/12/16/428691.html#Feedback0http://m.tkk7.com/paulwong/comments/commentRss/428691.htmlhttp://m.tkk7.com/paulwong/services/trackbacks/428691.html闃呰鍏ㄦ枃

paulwong 2015-12-16 18:50 鍙戣〃璇勮
]]>
MONGODB鍒犻櫎/鏂板/鏇存敼澶ч噺璁板綍鐨勬柟娉?/title><link>http://m.tkk7.com/paulwong/archive/2015/12/11/428617.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Fri, 11 Dec 2015 07:03:00 GMT</pubDate><guid>http://m.tkk7.com/paulwong/archive/2015/12/11/428617.html</guid><wfw:comment>http://m.tkk7.com/paulwong/comments/428617.html</wfw:comment><comments>http://m.tkk7.com/paulwong/archive/2015/12/11/428617.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/paulwong/comments/commentRss/428617.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/paulwong/services/trackbacks/428617.html</trackback:ping><description><![CDATA[MONGODB涓紝鐢變簬鍒犻櫎澶ч噺璁板綍浼?xì)鍗佸垎鑰楁椂錛屼竴鑸帹鑽愮敱MONGODB鑷繁鍦ㄥ悗鍙板鐞嗭紝鍙渶鍦ㄦ煇涓瓧孌佃涓涓儲(chǔ)寮曠殑鏍囩鍗沖彲銆?br /><br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->@Indexed(expireAfterSeconds=180)<br /><span style="color: #0000FF; ">private</span> Date deletedAt;</div><br /><span style="color: red;">浠ヤ笂浠g爜錛屽鏋滃瓧孌?/span><span style="font-size: 13px; color: red; background-color: #eeeeee;">deletedAt</span><span style="color: red;">鏈夊鹼紝閭d箞灝嗗湪180縐掑悗琚玀ONGODB鍒犻櫎錛屽鏋滄病鍊間笉浼?xì)琚垹闄ゃ?/span><br /><br />鎵歸噺鏂板錛屽皬鎵歸噺鏇存柊錛岄槻姝㈣鍙栬秴鏃?br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; ">private</span> <T> <span style="color: #0000FF; ">void</span> insertAll(List<T> list) {<br />        <span style="color: #0000FF; ">if</span> (<span style="color: #0000FF; ">null</span> != list) {<br />            <span style="color: #0000FF; ">int</span> total = list.size();<br />            <span style="color: #0000FF; ">int</span> count = (total + 50000 -1) / 50000;<br />            <span style="color: #0000FF; ">for</span> (<span style="color: #0000FF; ">int</span> i = 0; i < count; i++) {<br />                <span style="color: #0000FF; ">int</span> toIndex = ((i +1) * 50000 > total) ? total : ((i +1) * 50000);<br />                log.info("toIndex = " + toIndex);<br />                mongoTemplate1.insertAll(list.subList(i * 50000, toIndex));<br />            }<br />        }<br />    }</div><br />鎵歸噺鏇存敼<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; ">import</span> java.util.Date;<br /><br /><span style="color: #0000FF; ">import</span> org.springframework.beans.factory.annotation.Autowired;<br /><span style="color: #0000FF; ">import</span> org.springframework.data.mongodb.core.MongoTemplate;<br /><span style="color: #0000FF; ">import</span> org.springframework.data.mongodb.core.query.Criteria;<br /><span style="color: #0000FF; ">import</span> org.springframework.data.mongodb.core.query.Query;<br /><span style="color: #0000FF; ">import</span> org.springframework.data.mongodb.core.query.Update;<br /><br /><span style="color: #0000FF; ">import</span> com.tcl.project7.boss.gameapplication.yearendactivities.bigwheelgame.valueobject.SingleUseRedeemCode;<br /><br /><span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">class</span> SingleUseRedeemCodeRepositoryImpl <span style="color: #0000FF; ">implements</span> SingleUseRedeemCodeRepositoryCustom{<br />    <br />    @Autowired<br />    <span style="color: #0000FF; ">private</span> MongoTemplate mongoTemplate1;<br />    <br />    <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">void</span> batchUpdateSingleUseRedeemCodeList(String bigWheelGameAwardId) {<br />        <br />        Query query = <span style="color: #0000FF; ">new</span> Query();<br />        query.addCriteria(Criteria.where("bigwheelgameawardid").is(bigWheelGameAwardId));<br />        mongoTemplate1.updateMulti(<br />                                    query, <br />                                    <span style="color: #0000FF; ">new</span> Update().set("bigwheelgameawardid", "-1")<br />                                        .set("deletedat", <span style="color: #0000FF; ">new</span> Date()), <br />                                    SingleUseRedeemCode.<span style="color: #0000FF; ">class</span>);<br />    }<br /><br />}</div><br /><br /><h1>Expire Data from Collections by Setting TTL<a title="Permalink to this headline" style="box-sizing: border-box; color: #c60f0f; text-decoration: none; visibility: visible; font-size: 0.8em; padding: 0px 4px;">¶</a></h1><div style="box-sizing: border-box; color: #494747; font-family: Akzidenz, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px; background-color: #ffffff;"><p style="box-sizing: border-box; margin: 24px 0px;"><span style="box-sizing: border-box; font-style: italic;">New in version 2.2.</span></p></div><p style="box-sizing: border-box; margin: 24px 0px; color: #494747; font-family: Akzidenz, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px; background-color: #ffffff;">This document provides an introduction to MongoDB’s “<em style="box-sizing: border-box;">time to live</em>” or <a internal"="" style="box-sizing: border-box; color: #006cbc; text-decoration: none;">TTL</a> collection feature. TTL collections make it possible to store data in MongoDB and have the <a internal"="" title="mongod" style="box-sizing: border-box; color: #006cbc; text-decoration: none;"><tt mongodb="" mongodb-program="" docutils="" literal"="" style="box-sizing: border-box; font-family: 'Source Code Pro', monospace; background-color: transparent;">mongod</tt></a> automatically remove data after a specified number of seconds or at a specific clock time.</p><p style="box-sizing: border-box; margin: 24px 0px; color: #494747; font-family: Akzidenz, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px; background-color: #ffffff;">Data expiration is useful for some classes of information, including machine generated event data, logs, and session information that only need to persist for a limited period of time.</p><p style="box-sizing: border-box; margin: 24px 0px; color: #494747; font-family: Akzidenz, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px; background-color: #ffffff;">A special <a internal"="" style="box-sizing: border-box; color: #006cbc; text-decoration: none;">TTL index property</a> supports the implementation of TTL collections. The TTL feature relies on a background thread in <a internal"="" title="mongod" style="box-sizing: border-box; color: #006cbc; text-decoration: none;"><tt mongodb="" mongodb-program="" docutils="" literal"="" style="box-sizing: border-box; font-family: 'Source Code Pro', monospace; background-color: transparent;">mongod</tt></a> that reads the date-typed values in the index and removes expired <a internal"="" style="box-sizing: border-box; color: #006cbc; text-decoration: none;">documents</a>from the collection.</p><div class="6swg8s0" id="procedures" style="box-sizing: border-box; margin-top: 48px; color: #494747; font-family: Akzidenz, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px; background-color: #ffffff;"><h2>Procedures<a title="Permalink to this headline" style="box-sizing: border-box; color: #c60f0f; text-decoration: none; visibility: hidden; font-size: 0.8em; padding: 0px 4px;"></a></h2><p style="box-sizing: border-box; margin: 24px 0px; padding: 0px;">To create a <a internal"="" style="box-sizing: border-box; color: #006cbc; text-decoration: none;">TTL index</a>, use the <a internal"="" title="db.collection.createIndex()" style="box-sizing: border-box; color: #006cbc; text-decoration: none;"><tt mongodb="" mongodb-method="" docutils="" literal"="" style="box-sizing: border-box; font-family: 'Source Code Pro', monospace; background-color: transparent;">db.collection.createIndex()</tt></a> method with the<tt literal"="" style="box-sizing: border-box; color: #000000; font-family: 'Source Code Pro', monospace;">expireAfterSeconds</tt> option on a field whose value is either a <a internal"="" style="box-sizing: border-box; color: #006cbc; text-decoration: none;">date</a> or an array that contains <a internal"="" style="box-sizing: border-box; color: #006cbc; text-decoration: none;">date values</a>.</p><div note"="" style="box-sizing: border-box; margin: 24px 0px; padding: 2px 12px 22px; width: auto; max-width: 100%; border-left-width: 5px; border-left-style: solid; border-color: #6ba442; background-color: #edf4e8;"><p admonition-title"="" style="box-sizing: border-box; margin: 0px; font-weight: bold; font-size: 12px; text-transform: uppercase; color: #89b668;">NOTE</p><p style="box-sizing: border-box; margin: 0px;">The TTL index is a single field index. Compound indexes do not support the TTL property. For more information on TTL indexes, see <a internal"="" style="box-sizing: border-box; color: #006cbc; text-decoration: none;">TTL Indexes</a>.</p></div><div class="ek00yce" id="expire-documents-after-a-specified-number-of-seconds" style="box-sizing: border-box; margin-top: 48px;"><h3>Expire Documents after a Specified Number of Seconds<a title="Permalink to this headline" style="box-sizing: border-box; color: #c60f0f; text-decoration: none; visibility: hidden; font-size: 0.8em; padding: 0px 4px;"></a></h3><p style="box-sizing: border-box; margin: 0px 0px 24px; padding: 0px;">To expire data after a specified number of seconds has passed since the indexed field, create a TTL index on a field that holds values of BSON date type or an array of BSON date-typed objects <em style="box-sizing: border-box;">and</em> specify a positive non-zero value in the <tt literal"="" style="box-sizing: border-box; color: #000000; font-family: 'Source Code Pro', monospace;">expireAfterSeconds</tt> field. A document will expire when the number of seconds in the <tt literal"="" style="box-sizing: border-box; color: #000000; font-family: 'Source Code Pro', monospace;">expireAfterSeconds</tt> field has passed since the time specified in its indexed field. <a id="id1" style="box-sizing: border-box; color: #006cbc; text-decoration: none;">[1]</a></p><p style="box-sizing: border-box; margin: 24px 0px;">For example, the following operation creates an index on the <tt literal"="" style="box-sizing: border-box; color: #000000; font-family: 'Source Code Pro', monospace;">log_events</tt> collection’s <tt literal"="" style="box-sizing: border-box; color: #000000; font-family: 'Source Code Pro', monospace;">createdAt</tt> field and specifies the <tt literal"="" style="box-sizing: border-box; color: #000000; font-family: 'Source Code Pro', monospace;">expireAfterSeconds</tt> value of <tt literal"="" style="box-sizing: border-box; color: #000000; font-family: 'Source Code Pro', monospace;">3600</tt> to set the expiration time to be one hour after the time specified by <tt literal"="" style="box-sizing: border-box; color: #000000; font-family: 'Source Code Pro', monospace;">createdAt</tt>.</p><div style="box-sizing: border-box;"><div style="box-sizing: border-box; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><pre style="box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; padding: 24px 12px; margin-top: 24px; margin-bottom: 24px; word-break: break-all; word-wrap: normal; color: #222222; border-left-width: 5px; border-style: none none none solid; border-left-color: #494747; border-radius: 0px; overflow: auto; background: url("https://media.mongodb.org/code-block-bg.png") 0px 0px repeat #f5f6f7;"><span style="box-sizing: border-box;">db</span><span style="box-sizing: border-box;">.</span><span style="box-sizing: border-box;">log_events</span><span style="box-sizing: border-box;">.</span><span style="box-sizing: border-box;">createIndex</span><span style="box-sizing: border-box;">(</span> <span style="box-sizing: border-box;">{</span> <span style="box-sizing: border-box; color: #4070a0;">"createdAt"</span><span style="box-sizing: border-box; color: #666666;">:</span> <span style="box-sizing: border-box; color: #208050;">1</span> <span style="box-sizing: border-box;">},</span> <span style="box-sizing: border-box;">{</span> <span style="box-sizing: border-box;">expireAfterSeconds</span><span style="box-sizing: border-box; color: #666666;">:</span> <span style="box-sizing: border-box; color: #208050;">3600</span> <span style="box-sizing: border-box;">}</span> <span style="box-sizing: border-box;">)</span> </pre></div></div><p style="box-sizing: border-box; margin: 24px 0px;">When adding documents to the <tt literal"="" style="box-sizing: border-box; color: #000000; font-family: 'Source Code Pro', monospace;">log_events</tt> collection, set the <tt literal"="" style="box-sizing: border-box; color: #000000; font-family: 'Source Code Pro', monospace;">createdAt</tt> field to the current time:</p><div style="box-sizing: border-box;"><div style="box-sizing: border-box; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><pre style="box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; padding: 24px 12px; margin-top: 24px; margin-bottom: 24px; word-break: break-all; word-wrap: normal; color: #222222; border-left-width: 5px; border-style: none none none solid; border-left-color: #494747; border-radius: 0px; overflow: auto; background: url("https://media.mongodb.org/code-block-bg.png") 0px 0px repeat #f5f6f7;"><span style="box-sizing: border-box;">db</span><span style="box-sizing: border-box;">.</span><span style="box-sizing: border-box;">log_events</span><span style="box-sizing: border-box;">.</span><span style="box-sizing: border-box;">insert</span><span style="box-sizing: border-box;">(</span> <span style="box-sizing: border-box;">{</span> <span style="box-sizing: border-box; color: #4070a0;">"createdAt"</span><span style="box-sizing: border-box; color: #666666;">:</span> <span style="box-sizing: border-box; color: #007020; font-weight: bold;">new</span> <span style="box-sizing: border-box; color: #007020;">Date</span><span style="box-sizing: border-box;">(),</span> <span style="box-sizing: border-box; color: #4070a0;">"logEvent"</span><span style="box-sizing: border-box; color: #666666;">:</span> <span style="box-sizing: border-box; color: #208050;">2</span><span style="box-sizing: border-box;">,</span> <span style="box-sizing: border-box; color: #4070a0;">"logMessage"</span><span style="box-sizing: border-box; color: #666666;">:</span> <span style="box-sizing: border-box; color: #4070a0;">"Success!"</span> <span style="box-sizing: border-box;">}</span> <span style="box-sizing: border-box;">)</span> </pre></div></div><p style="box-sizing: border-box; margin: 24px 0px;">MongoDB will automatically delete documents from the <tt literal"="" style="box-sizing: border-box; color: #000000; font-family: 'Source Code Pro', monospace;">log_events</tt> collection when the document’s<tt literal"="" style="box-sizing: border-box; color: #000000; font-family: 'Source Code Pro', monospace;">createdAt</tt> value <a id="id2" style="box-sizing: border-box; color: #006cbc; text-decoration: none;">[1]</a> is older than the number of seconds specified in <tt literal"="" style="box-sizing: border-box; color: #000000; font-family: 'Source Code Pro', monospace;">expireAfterSeconds</tt>.</p><table footnote"="" frame="void" id="field-is-array-of-dates" rules="none" style="box-sizing: border-box; border-collapse: collapse; border-spacing: 0px; max-width: 100%; border: 0px; font-size: 14px; line-height: 24px; margin: 24px 0px; background-color: transparent;"><colgroup style="box-sizing: border-box;"><col style="box-sizing: border-box;"><col style="box-sizing: border-box;"></colgroup><tbody valign="top" style="box-sizing: border-box;"><tr style="box-sizing: border-box;"><td style="box-sizing: border-box; padding: 11px 5px 12px; border: 0px #ebebed !important;">[1]</td><td style="box-sizing: border-box; padding: 11px 5px 12px; border: 0px #ebebed !important;"><em style="box-sizing: border-box;">(<a style="box-sizing: border-box; color: #006cbc; text-decoration: none;">1</a>, <a style="box-sizing: border-box; color: #006cbc; text-decoration: none;">2</a>)</em> If the field contains an array of BSON date-typed objects, data expires if at least one of BSON date-typed object is older than the number of seconds specified in <tt literal"="" style="box-sizing: border-box; font-family: 'Source Code Pro', monospace;">expireAfterSeconds</tt>.</td></tr></tbody></table><div seealso"="" style="box-sizing: border-box; margin: 24px 0px; padding: 2px 12px 22px; width: auto; max-width: 100%; border-left-width: 5px; border-left-style: solid; border-left-color: transparent;"><p admonition-title"="" style="box-sizing: border-box; margin: 0px; font-weight: bold; font-size: 12px; text-transform: uppercase;">SEE ALSO</p><p style="box-sizing: border-box; margin: 0px;"><a internal"="" title="$currentDate" style="box-sizing: border-box; color: #006cbc; text-decoration: none;"><tt mongodb="" mongodb-update="" docutils="" literal"="" style="box-sizing: border-box; font-family: 'Source Code Pro', monospace; background-color: transparent;">$currentDate</tt></a> operator</p></div></div><div class="u00io6e" id="expire-documents-at-a-specific-clock-time" style="box-sizing: border-box; margin-top: 48px;"><h3>Expire Documents at a Specific Clock Time<a title="Permalink to this headline" style="box-sizing: border-box; color: #c60f0f; text-decoration: none; visibility: hidden; font-size: 0.8em; padding: 0px 4px;"></a></h3><p style="box-sizing: border-box; margin: 0px 0px 24px; padding: 0px;">To expire documents at a specific clock time, begin by creating a TTL index on a field that holds values of BSON date type or an array of BSON date-typed objects <em style="box-sizing: border-box;">and</em> specify an <tt literal"="" style="box-sizing: border-box; color: #000000; font-family: 'Source Code Pro', monospace;">expireAfterSeconds</tt> value of<tt literal"="" style="box-sizing: border-box; color: #000000; font-family: 'Source Code Pro', monospace;">0</tt>. For each document in the collection, set the indexed date field to a value corresponding to the time the document should expire. If the indexed date field contains a date in the past, MongoDB considers the document expired.</p><p style="box-sizing: border-box; margin: 24px 0px;">For example, the following operation creates an index on the <tt literal"="" style="box-sizing: border-box; color: #000000; font-family: 'Source Code Pro', monospace;">log_events</tt> collection’s <tt literal"="" style="box-sizing: border-box; color: #000000; font-family: 'Source Code Pro', monospace;">expireAt</tt> field and specifies the <tt literal"="" style="box-sizing: border-box; color: #000000; font-family: 'Source Code Pro', monospace;">expireAfterSeconds</tt> value of <tt literal"="" style="box-sizing: border-box; color: #000000; font-family: 'Source Code Pro', monospace;">0</tt>:</p><div style="box-sizing: border-box;"><div style="box-sizing: border-box; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><pre style="box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; padding: 24px 12px; margin-top: 24px; margin-bottom: 24px; word-break: break-all; word-wrap: normal; color: #222222; border-left-width: 5px; border-style: none none none solid; border-left-color: #494747; border-radius: 0px; overflow: auto; background: url("https://media.mongodb.org/code-block-bg.png") 0px 0px repeat #f5f6f7;"><span style="box-sizing: border-box;">db</span><span style="box-sizing: border-box;">.</span><span style="box-sizing: border-box;">log_events</span><span style="box-sizing: border-box;">.</span><span style="box-sizing: border-box;">createIndex</span><span style="box-sizing: border-box;">(</span> <span style="box-sizing: border-box;">{</span> <span style="box-sizing: border-box; color: #4070a0;">"expireAt"</span><span style="box-sizing: border-box; color: #666666;">:</span> <span style="box-sizing: border-box; color: #208050;">1</span> <span style="box-sizing: border-box;">},</span> <span style="box-sizing: border-box;">{</span> <span style="box-sizing: border-box;">expireAfterSeconds</span><span style="box-sizing: border-box; color: #666666;">:</span> <span style="box-sizing: border-box; color: #208050;">0</span> <span style="box-sizing: border-box;">}</span> <span style="box-sizing: border-box;">)</span> </pre></div></div><p style="box-sizing: border-box; margin: 24px 0px;">For each document, set the value of <tt literal"="" style="box-sizing: border-box; color: #000000; font-family: 'Source Code Pro', monospace;">expireAt</tt> to correspond to the time the document should expire. For instance, the following <a internal"="" title="db.collection.insert()" style="box-sizing: border-box; color: #006cbc; text-decoration: none;"><tt mongodb="" mongodb-method="" docutils="" literal"="" style="box-sizing: border-box; font-family: 'Source Code Pro', monospace; background-color: transparent;">insert()</tt></a> operation adds a document that should expire at <tt literal"="" style="box-sizing: border-box; color: #000000; font-family: 'Source Code Pro', monospace;"><span style="box-sizing: border-box;">July</span> <span style="box-sizing: border-box;">22,</span> <span style="box-sizing: border-box;">2013</span><span style="box-sizing: border-box;">14:00:00</span></tt>.</p><div style="box-sizing: border-box;"><div style="box-sizing: border-box; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><pre style="box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; padding: 24px 12px; margin-top: 24px; margin-bottom: 24px; word-break: break-all; word-wrap: normal; color: #222222; border-left-width: 5px; border-style: none none none solid; border-left-color: #494747; border-radius: 0px; overflow: auto; background: url("https://media.mongodb.org/code-block-bg.png") 0px 0px repeat #f5f6f7;"><span style="box-sizing: border-box;">db</span><span style="box-sizing: border-box;">.</span><span style="box-sizing: border-box;">log_events</span><span style="box-sizing: border-box;">.</span><span style="box-sizing: border-box;">insert</span><span style="box-sizing: border-box;">(</span> <span style="box-sizing: border-box;">{</span> <span style="box-sizing: border-box; color: #4070a0;">"expireAt"</span><span style="box-sizing: border-box; color: #666666;">:</span> <span style="box-sizing: border-box; color: #007020; font-weight: bold;">new</span> <span style="box-sizing: border-box; color: #007020;">Date</span><span style="box-sizing: border-box;">(</span><span style="box-sizing: border-box; color: #4070a0;">'July 22, 2013 14:00:00'</span><span style="box-sizing: border-box;">),</span> <span style="box-sizing: border-box; color: #4070a0;">"logEvent"</span><span style="box-sizing: border-box; color: #666666;">:</span> <span style="box-sizing: border-box; color: #208050;">2</span><span style="box-sizing: border-box;">,</span> <span style="box-sizing: border-box; color: #4070a0;">"logMessage"</span><span style="box-sizing: border-box; color: #666666;">:</span> <span style="box-sizing: border-box; color: #4070a0;">"Success!"</span> <span style="box-sizing: border-box;">}</span> <span style="box-sizing: border-box;">)</span> </pre></div></div><p style="box-sizing: border-box; margin: 24px 0px;">MongoDB will automatically delete documents from the <tt literal"="" style="box-sizing: border-box; color: #000000; font-family: 'Source Code Pro', monospace;">log_events</tt> collection when the documents’<tt literal"="" style="box-sizing: border-box; color: #000000; font-family: 'Source Code Pro', monospace;">expireAt</tt> value is older than the number of seconds specified in <tt literal"="" style="box-sizing: border-box; color: #000000; font-family: 'Source Code Pro', monospace;">expireAfterSeconds</tt>, i.e. <tt literal"="" style="box-sizing: border-box; color: #000000; font-family: 'Source Code Pro', monospace;">0</tt> seconds older in this case. As such, the data expires at the specified <tt literal"="" style="box-sizing: border-box; color: #000000; font-family: 'Source Code Pro', monospace;">expireAt</tt> value.</p></div></div><img src ="http://m.tkk7.com/paulwong/aggbug/428617.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/paulwong/" target="_blank">paulwong</a> 2015-12-11 15:03 <a href="http://m.tkk7.com/paulwong/archive/2015/12/11/428617.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>How to delete large amount of data of a MongoDB collection 鈥渜uickly鈥?/title><link>http://m.tkk7.com/paulwong/archive/2015/12/10/428601.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Thu, 10 Dec 2015 12:09:00 GMT</pubDate><guid>http://m.tkk7.com/paulwong/archive/2015/12/10/428601.html</guid><wfw:comment>http://m.tkk7.com/paulwong/comments/428601.html</wfw:comment><comments>http://m.tkk7.com/paulwong/archive/2015/12/10/428601.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/paulwong/comments/commentRss/428601.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/paulwong/services/trackbacks/428601.html</trackback:ping><description><![CDATA[<p style="margin: 0px 0px 20px; padding: 0px; color: #626566; font-family: Georgia, serif; font-size: 13px; line-height: 20.8px; background-color: #ffffff;">We have a db collection that is around 30 million documents, and I need to trim it down, to only keeping the documents created on the last month. </p><p style="margin: 0px 0px 20px; padding: 0px; color: #626566; font-family: Georgia, serif; font-size: 13px; line-height: 20.8px; background-color: #ffffff;">One approach would be use the <code style="font-family: Monaco, Consolas, 'Courier New', monospace;">remove</code> command with a condition on the <code style="font-family: Monaco, Consolas, 'Courier New', monospace;">created_at</code> field (the collection already have an index on this field):</p><pre js"="" style="margin-top: 10px; margin-bottom: 10px; padding: 10px; font-family: Monaco, Consolas, 'Courier New', monospace; text-shadow: #ffffff 0px 1px; overflow: auto; color: #626566; font-size: 13px; line-height: 20.8px; background: #eeeeee;">db.my_collection.remove({created_at: {$lte: new Date("11/01/2012")}});</pre><p style="margin: 0px 0px 20px; padding: 0px; color: #626566; font-family: Georgia, serif; font-size: 13px; line-height: 20.8px; background-color: #ffffff;">But this approach will be very slow, instead of that, a better way to do it is rename the current collection (for instance to “old_collection”) using <code style="font-family: Monaco, Consolas, 'Courier New', monospace;">renameCollection</code>. Then performing a query-and-insert from the “old_collection” into “my_collection”:</p><pre js"="" style="margin-top: 10px; margin-bottom: 10px; padding: 10px; font-family: Monaco, Consolas, 'Courier New', monospace; text-shadow: #ffffff 0px 1px; overflow: auto; color: #626566; font-size: 13px; line-height: 20.8px; background: #eeeeee;">db.my_collection.renameCollection("old_collection"); <br />db.createCollection("my_collection"); <br />db.my_collection.createIndex(...); // recreate the indexes for the collection <br />// copy docs from old collection into the new collection <br />db.old_collection.find( <br />{created_at: {$gte: new Date("11/01/2012")}} ).sort({_id: -1}).forEach( <br />function(row) { db.my_collection.insert(row); } ); // drop old collection db.old_collection.drop(); </pre><p style="margin: 0px 0px 20px; padding: 0px; color: #626566; font-family: Georgia, serif; font-size: 13px; line-height: 20.8px; background-color: #ffffff;">This approach is typically faster than running a bunch of removes on your data</p><img src ="http://m.tkk7.com/paulwong/aggbug/428601.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/paulwong/" target="_blank">paulwong</a> 2015-12-10 20:09 <a href="http://m.tkk7.com/paulwong/archive/2015/12/10/428601.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>MongoDB 鍥哄畾闆嗗悎(Capped Collections)http://m.tkk7.com/paulwong/archive/2015/12/09/428576.htmlpaulwongpaulwongWed, 09 Dec 2015 06:41:00 GMThttp://m.tkk7.com/paulwong/archive/2015/12/09/428576.htmlhttp://m.tkk7.com/paulwong/comments/428576.htmlhttp://m.tkk7.com/paulwong/archive/2015/12/09/428576.html#Feedback0http://m.tkk7.com/paulwong/comments/commentRss/428576.htmlhttp://m.tkk7.com/paulwong/services/trackbacks/428576.htmlMongoDB 鍥哄畾闆嗗悎錛圕apped Collections錛夋槸鎬ц兘鍑鴻壊涓旀湁鐫鍥哄畾澶у皬鐨勯泦鍚堬紝瀵逛簬澶у皬鍥哄畾錛屾垜浠彲浠ユ兂璞″叾灝卞儚涓涓幆褰㈤槦鍒楋紝褰撻泦鍚堢┖闂寸敤瀹屽悗錛屽啀鎻掑叆鐨勫厓绱犲氨浼?xì)瑕嗙洊鏈鍒濆鐨勫ご閮ㄧ殑鍏冪礌錛?/p>

鍒涘緩鍥哄畾闆嗗悎

鎴戜滑閫氳繃createCollection鏉ュ垱寤轟竴涓浐瀹氶泦鍚堬紝涓攃apped閫夐」璁劇疆涓簍rue錛?/p>

>db.createCollection("cappedLogCollection",{capped:true,size:10000})

榪樺彲浠ユ寚瀹氭枃妗d釜鏁?鍔犱笂max:1000灞炴э細(xì)

>db.createCollection("cappedLogCollection",{capped:true,size:10000,max:1000})

鍒ゆ柇闆嗗悎鏄惁涓哄浐瀹氶泦鍚?

>db.cappedLogCollection.isCapped()

濡傛灉闇瑕佸皢宸插瓨鍦ㄧ殑闆嗗悎杞崲涓哄浐瀹氶泦鍚堝彲浠ヤ嬌鐢ㄤ互涓嬪懡浠わ細(xì)

>db.runCommand({"convertToCapped":"posts",size:10000})

浠ヤ笂浠g爜灝嗘垜浠凡瀛樺湪鐨?posts 闆嗗悎杞崲涓哄浐瀹氶泦鍚堛?/p>


鍥哄畾闆嗗悎鏌ヨ

鍥哄畾闆嗗悎鏂囨。鎸夌収鎻掑叆欏哄簭鍌ㄥ瓨鐨?榛樿鎯呭喌涓嬫煡璇㈠氨鏄寜鐓ф彃鍏ラ『搴忚繑鍥炵殑,涔熷彲浠ヤ嬌鐢?natural璋冩暣榪斿洖欏哄簭銆?/p>

>db.cappedLogCollection.find().sort({$natural:-1})

鍥哄畾闆嗗悎鐨勫姛鑳界壒鐐?/h2>

鍙互鎻掑叆鍙?qiáng)鏇存?浣嗘洿鏂頒笉鑳借秴鍑篶ollection鐨勫ぇ灝?鍚﹀垯鏇存柊澶辮觸,涓嶅厑璁稿垹闄?浣嗘槸鍙互璋冪敤drop()鍒犻櫎闆嗗悎涓殑鎵鏈夎,浣嗘槸drop鍚庨渶瑕佹樉寮忓湴閲嶅緩闆嗗悎銆?/p>

鍦?2浣嶆満瀛愪笂涓涓猚appped collection鐨勬渶澶у肩害涓?82.5M,64浣嶄笂鍙彈緋葷粺鏂囦歡澶у皬鐨勯檺鍒躲?/p>


鍥哄畾闆嗗悎灞炴у強(qiáng)鐢ㄦ硶

灞炴?/h3>
  • 灞炴?:瀵瑰浐瀹氶泦鍚堣繘琛屾彃鍏ラ熷害鏋佸揩
  • 灞炴?:鎸夌収鎻掑叆欏哄簭鐨勬煡璇㈣緭鍑洪熷害鏋佸揩
  • 灞炴?:鑳藉鍦ㄦ彃鍏ユ渶鏂版暟鎹椂,娣樻卑鏈鏃╃殑鏁版嵁

鐢ㄦ硶

  • 鐢ㄦ硶1:鍌ㄥ瓨鏃ュ織淇℃伅
  • 鐢ㄦ硶2:緙撳瓨涓浜涘皯閲忕殑鏂囨。


paulwong 2015-12-09 14:41 鍙戣〃璇勮
]]>
MongoDB 鑱氬悎http://m.tkk7.com/paulwong/archive/2015/12/08/428558.htmlpaulwongpaulwongTue, 08 Dec 2015 02:44:00 GMThttp://m.tkk7.com/paulwong/archive/2015/12/08/428558.htmlhttp://m.tkk7.com/paulwong/comments/428558.htmlhttp://m.tkk7.com/paulwong/archive/2015/12/08/428558.html#Feedback0http://m.tkk7.com/paulwong/comments/commentRss/428558.htmlhttp://m.tkk7.com/paulwong/services/trackbacks/428558.htmlhttp://www.runoob.com/mongodb/mongodb-aggregate.html
MongoDB涓仛鍚?aggregate)涓昏鐢ㄤ簬澶勭悊鏁版嵁(璇稿緇熻騫沖潎鍊?姹傚拰絳?錛屽茍榪斿洖璁$畻鍚庣殑鏁版嵁緇撴灉銆傛湁鐐圭被浼約ql璇彞涓殑 count(*)銆?/p>

aggregate() 鏂規(guī)硶

MongoDB涓仛鍚堢殑鏂規(guī)硶浣跨敤aggregate()銆?/p>

璇硶

aggregate() 鏂規(guī)硶鐨勫熀鏈娉曟牸寮忓涓嬫墍紺猴細(xì)

>db.COLLECTION_NAME.aggregate(AGGREGATE_OPERATION)

瀹炰緥

闆嗗悎涓殑鏁版嵁濡備笅錛?/p>

{    _id: ObjectId(7df78ad8902c)    title: 'MongoDB Overview',     description: 'MongoDB is no sql database',    by_user: 'w3cschool.cc',    url: 'http://www.w3cschool.cc',    tags: ['mongodb', 'database', 'NoSQL'],    likes: 100 }, {    _id: ObjectId(7df78ad8902d)    title: 'NoSQL Overview',     description: 'No sql database is very fast',    by_user: 'w3cschool.cc',    url: 'http://www.w3cschool.cc',    tags: ['mongodb', 'database', 'NoSQL'],    likes: 10 }, {    _id: ObjectId(7df78ad8902e)    title: 'Neo4j Overview',     description: 'Neo4j is no sql database',    by_user: 'Neo4j',    url: 'http://www.neo4j.com',    tags: ['neo4j', 'database', 'NoSQL'],    likes: 750 },

鐜板湪鎴戜滑閫氳繃浠ヤ笂闆嗗悎璁$畻姣忎釜浣滆呮墍鍐欑殑鏂囩珷鏁幫紝浣跨敤aggregate()璁$畻緇撴灉濡備笅錛?/p>

> db.mycol.aggregate([{$group : {_id : "$by_user", num_tutorial : {$sum : 1}}}]) { "result" : [ { "_id" : "w3cschool.cc", "num_tutorial" : 2 }, { "_id" : "Neo4j", "num_tutorial" : 1 } ], "ok" : 1 } >

浠ヤ笂瀹炰緥綾諱技sql璇彞錛?em style="border: 0px; margin: 0px; padding: 0px;"> select by_user, count(*) from mycol group by by_user

鍦ㄤ笂闈㈢殑渚嬪瓙涓紝鎴戜滑閫氳繃瀛楁by_user瀛楁瀵規(guī)暟鎹繘琛屽垎緇勶紝騫惰綆梑y_user瀛楁鐩稿悓鍊肩殑鎬誨拰銆?/p>

涓嬭〃灞曠ず浜嗕竴浜涜仛鍚堢殑琛ㄨ揪寮?

琛ㄨ揪寮?/th>鎻忚堪瀹炰緥
$sum璁$畻鎬誨拰銆?/td>db.mycol.aggregate([{$group : {_id : "$by_user", num_tutorial : {$sum : "$likes"}}}])
$avg璁$畻騫沖潎鍊?/td>db.mycol.aggregate([{$group : {_id : "$by_user", num_tutorial : {$avg : "$likes"}}}])
$min鑾峰彇闆嗗悎涓墍鏈夋枃妗e搴斿煎緱鏈灝忓箋?/td>db.mycol.aggregate([{$group : {_id : "$by_user", num_tutorial : {$min : "$likes"}}}])
$max鑾峰彇闆嗗悎涓墍鏈夋枃妗e搴斿煎緱鏈澶у箋?/td>db.mycol.aggregate([{$group : {_id : "$by_user", num_tutorial : {$max : "$likes"}}}])
$push鍦ㄧ粨鏋滄枃妗d腑鎻掑叆鍊煎埌涓涓暟緇勪腑銆?/td>db.mycol.aggregate([{$group : {_id : "$by_user", url : {$push: "$url"}}}])
$addToSet鍦ㄧ粨鏋滄枃妗d腑鎻掑叆鍊煎埌涓涓暟緇勪腑錛屼絾涓嶅垱寤哄壇鏈?/td>db.mycol.aggregate([{$group : {_id : "$by_user", url : {$addToSet : "$url"}}}])
$first鏍規(guī)嵁璧勬簮鏂囨。鐨勬帓搴忚幏鍙栫涓涓枃妗f暟鎹?/td>db.mycol.aggregate([{$group : {_id : "$by_user", first_url : {$first : "$url"}}}])
$last鏍規(guī)嵁璧勬簮鏂囨。鐨勬帓搴忚幏鍙栨渶鍚庝竴涓枃妗f暟鎹?/td>db.mycol.aggregate([{$group : {_id : "$by_user", last_url : {$last : "$url"}}}])

綆¢亾鐨勬蹇?/h2>

綆¢亾鍦║nix鍜孡inux涓竴鑸敤浜庡皢褰撳墠鍛戒護(hù)鐨勮緭鍑虹粨鏋滀綔涓轟笅涓涓懡浠ょ殑鍙傛暟銆?/p>

MongoDB鐨勮仛鍚堢閬撳皢MongoDB鏂囨。鍦ㄤ竴涓閬撳鐞嗗畬姣曞悗灝嗙粨鏋滀紶閫掔粰涓嬩竴涓閬撳鐞嗐傜閬撴搷浣滄槸鍙互閲嶅鐨勩?/p>

琛ㄨ揪寮忥細(xì)澶勭悊杈撳叆鏂囨。騫惰緭鍑恒傝〃杈懼紡鏄棤鐘舵佺殑錛屽彧鑳界敤浜庤綆楀綋鍓嶈仛鍚堢閬撶殑鏂囨。錛屼笉鑳藉鐞嗗叾瀹冪殑鏂囨。銆?/p>

榪欓噷鎴戜滑浠嬬粛涓涓嬭仛鍚堟鏋朵腑甯哥敤鐨勫嚑涓搷浣滐細(xì)

  • $project錛氫慨鏀硅緭鍏ユ枃妗g殑緇撴瀯銆傚彲浠ョ敤鏉ラ噸鍛藉悕銆佸鍔犳垨鍒犻櫎鍩燂紝涔熷彲浠ョ敤浜庡垱寤鴻綆楃粨鏋滀互鍙?qiáng)宓屽鏂囨。銆?/li>
  • $match錛氱敤浜庤繃婊ゆ暟鎹紝鍙緭鍑虹鍚堟潯浠剁殑鏂囨。銆?match浣跨敤MongoDB鐨勬爣鍑嗘煡璇㈡搷浣溿?/li>
  • $limit錛氱敤鏉ラ檺鍒禡ongoDB鑱氬悎綆¢亾榪斿洖鐨勬枃妗f暟銆?/li>
  • $skip錛氬湪鑱氬悎綆¢亾涓煩榪囨寚瀹氭暟閲忕殑鏂囨。錛屽茍榪斿洖浣欎笅鐨勬枃妗c?/li>
  • $unwind錛氬皢鏂囨。涓殑鏌愪竴涓暟緇勭被鍨嬪瓧孌墊媶鍒嗘垚澶氭潯錛屾瘡鏉″寘鍚暟緇勪腑鐨勪竴涓箋?/li>
  • $group錛氬皢闆嗗悎涓殑鏂囨。鍒嗙粍錛屽彲鐢ㄤ簬緇熻緇撴灉銆?/li>
  • $sort錛氬皢杈撳叆鏂囨。鎺掑簭鍚庤緭鍑恒?/li>
  • $geoNear錛氳緭鍑烘帴榪戞煇涓鍦扮悊浣嶇疆鐨勬湁搴忔枃妗c?/li>

綆¢亾鎿嶄綔絎﹀疄渚?/h3>

1銆?project瀹炰緥

db.article.aggregate( { $project : {         title : 1 ,         author : 1 , }} );

榪欐牱鐨勮瘽緇撴灉涓氨鍙繕鏈塤id,tilte鍜宎uthor涓変釜瀛楁浜嗭紝榛樿鎯呭喌涓媉id瀛楁鏄鍖呭惈鐨勶紝濡傛灉瑕佹兂涓嶅寘鍚玙id璇濆彲浠ヨ繖鏍?

db.article.aggregate( { $project : {         _id : 0 ,         title : 1 ,         author : 1 }});

2.$match瀹炰緥

db.articles.aggregate( [ { $match : { score : { $gt : 70, $lte : 90 } } }, { $group: { _id: null, count: { $sum: 1 } } } ] );

$match鐢ㄤ簬鑾峰彇鍒嗘暟澶т簬70灝忎簬鎴栫瓑浜?0璁板綍錛岀劧鍚庡皢絎﹀悎鏉′歡鐨勮褰曢佸埌涓嬩竴闃舵$group綆¢亾鎿嶄綔絎﹁繘琛屽鐞嗐?/p>

3.$skip瀹炰緥

db.article.aggregate( { $skip : 5 }); 

緇忚繃$skip綆¢亾鎿嶄綔絎﹀鐞嗗悗錛屽墠浜斾釜鏂囨。琚?榪囨護(hù)"鎺夈?/p>

paulwong 2015-12-08 10:44 鍙戣〃璇勮
]]>mongodb榪愮淮涔嬪壇鏈泦瀹炶返http://m.tkk7.com/paulwong/archive/2015/06/30/425955.htmlpaulwongpaulwongTue, 30 Jun 2015 02:30:00 GMThttp://m.tkk7.com/paulwong/archive/2015/06/30/425955.htmlhttp://m.tkk7.com/paulwong/comments/425955.htmlhttp://m.tkk7.com/paulwong/archive/2015/06/30/425955.html#Feedback0http://m.tkk7.com/paulwong/comments/commentRss/425955.htmlhttp://m.tkk7.com/paulwong/services/trackbacks/425955.html闃呰鍏ㄦ枃

paulwong 2015-06-30 10:30 鍙戣〃璇勮
]]>
MONGODB浼樺寲璧勬簮http://m.tkk7.com/paulwong/archive/2015/05/05/424867.htmlpaulwongpaulwongTue, 05 May 2015 09:32:00 GMThttp://m.tkk7.com/paulwong/archive/2015/05/05/424867.htmlhttp://m.tkk7.com/paulwong/comments/424867.htmlhttp://m.tkk7.com/paulwong/archive/2015/05/05/424867.html#Feedback0http://m.tkk7.com/paulwong/comments/commentRss/424867.htmlhttp://m.tkk7.com/paulwong/services/trackbacks/424867.htmlhttp://database.51cto.com/art/201309/411076.htm

Do you want a timeout?
http://blog.mongolab.com/2013/10/do-you-want-a-timeout/


MongoDB 鏌ヨ瓚呮椂寮傚父鐨勫師鍥犲強(qiáng)瑙e喅鍔炴硶
http://database.51cto.com/art/201503/467581.htm


Mongo榪炴帴姹犳搷浣淢ongoOptions
http://dawn-sky.iteye.com/blog/1343659




paulwong 2015-05-05 17:32 鍙戣〃璇勮
]]>
MONGODB甯哥敤鍛戒護(hù)http://m.tkk7.com/paulwong/archive/2015/04/15/424445.htmlpaulwongpaulwongWed, 15 Apr 2015 09:39:00 GMThttp://m.tkk7.com/paulwong/archive/2015/04/15/424445.htmlhttp://m.tkk7.com/paulwong/comments/424445.htmlhttp://m.tkk7.com/paulwong/archive/2015/04/15/424445.html#Feedback0http://m.tkk7.com/paulwong/comments/commentRss/424445.htmlhttp://m.tkk7.com/paulwong/services/trackbacks/424445.html
鍚姩錛?/span>
mongod --config /usr/local/mongodb/conf/cms.conf

鍏抽棴錛?/span>
ps -ef | grep mongo (鏌ID)
kill -15 pid

淇錛?/span>
rm /data/mongodb/mongod.lock
mongod --dbpath /data/mongodb --repair
mongod --config /usr/local/mongodb/conf/cms.conf

榪涘叆鍛戒護(hù)妯″紡錛?/span>
mongo admin -u root -p cloudDB

鏌ョ湅鏈嶅姟鍣ㄨ繛鎺ユ暟錛?/span>
db.serverStatus().connections

鏌ョ湅鐗堟湰錛?/span>
db.runCommand({"buildInfo":1})  

鏌ョ湅緇熻錛?/span>
mongostat -u root -p cloudDB

澶囦喚鏁版嵁錛?/span>
mongodump -u cms -p cms -d cms -o /data/dump/cms

鎭㈠鏁版嵁錛?/span>
mongorestore -u cms -p cms -d cms /data/dump/cms



paulwong 2015-04-15 17:39 鍙戣〃璇勮
]]>鍑犲ぇNOSQL鏁版嵁搴撴ц兘姣旇緝http://m.tkk7.com/paulwong/archive/2015/01/30/422565.htmlpaulwongpaulwongThu, 29 Jan 2015 16:16:00 GMThttp://m.tkk7.com/paulwong/archive/2015/01/30/422565.htmlhttp://m.tkk7.com/paulwong/comments/422565.htmlhttp://m.tkk7.com/paulwong/archive/2015/01/30/422565.html#Feedback0http://m.tkk7.com/paulwong/comments/commentRss/422565.htmlhttp://m.tkk7.com/paulwong/services/trackbacks/422565.htmlhttp://planetcassandra.org/nosql-performance-benchmarks

NoSQL Benchmarking
http://www.cubrid.org/blog/dev-platform/nosql-benchmarking/


http://www.badrit.com/blog/2013/11/18/redis-vs-mongodb-performance#.VMpfW2SUfsg

How many requests per second can I get out of Redis?
http://skipperkongen.dk/2013/08/27/how-many-requests-per-second-can-i-get-out-of-redis/

redis鎬ц兘嫻嬭瘯錛屾祴璇曞茍鍙戞ц兘
http://my.oschina.net/pblack/blog/102394

paulwong 2015-01-30 00:16 鍙戣〃璇勮
]]>
Mongodb 鏌ヨ鎬ц兘鐨勪簨鎯?/title><link>http://m.tkk7.com/paulwong/archive/2015/01/06/422096.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Tue, 06 Jan 2015 15:39:00 GMT</pubDate><guid>http://m.tkk7.com/paulwong/archive/2015/01/06/422096.html</guid><wfw:comment>http://m.tkk7.com/paulwong/comments/422096.html</wfw:comment><comments>http://m.tkk7.com/paulwong/archive/2015/01/06/422096.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/paulwong/comments/commentRss/422096.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/paulwong/services/trackbacks/422096.html</trackback:ping><description><![CDATA[涓婁竴綃囷細(xì)Mongodb VS Mysql 鏌ヨ鎬ц兘錛屾祴璇曚簡 mongodb 涓?mysql 鐨勬煡璇㈡ц兘銆傜粨鏋滆鏄?mongodb 鎬ц兘鍙互錛?鍙互浠f浛 mysql 鏉ヤ嬌鐢ㄣ?br /><br />浣嗘槸榪欎釜嫻嬭瘯閮芥槸鍦ㄧ櫨涓囩駭鍒紝鎴戠殑鍦烘櫙鍦?KW 綰у埆銆傛墍浠ヨ繕瑕佸 mongodb 鍦?kw 綰у埆涓嬫祴璇曟晥鏋溿?br /><br />鎴戞祴璇曠幆澧冩槸 4G 鍐呭瓨錛堟湁濂戒簺鍐呭瓨琚叾瀹冪▼搴忓崰鐢級錛?kw 鏁版嵁錛屾煡璇㈤殢鏈虹敓鎴?id錛堜竴嬈℃煡璇?20 涓猧d錛夈?br /><br />鍦ㄨ繖鏍風(fēng)殑鐜涓祴璇曚笉鐞嗘兂錛屾瘮杈冨け鏈涖傚鉤鍧囦竴嬈℃煡璇?500ms錛堟瘮 mysql 榪樺樊錛岀壒鍒槸鍦ㄥ茍鍙戞煡璇笅錛屾ц兘杈冨樊銆傚緢搴曠殑鍚炲悙閲忥級銆傛煡鐪嬪叾绱㈠紩澶у皬錛堢敤 db.mycoll.stats() 鍙互鏌ヨ錛夛細(xì)2kw 鏁版嵁涓湁 1.1G 宸﹀彸鐨勭儲(chǔ)寮曪紝瀛樺偍鐨勬暟鎹湪 11G 宸﹀彸銆?br /><br />嫻嬭瘯榪囩▼涓彂鐜?iowait 鍗?50% 宸﹀彸錛岀湅鏉ヨ繕鏄?io 鐨勭摱棰堛傝繕鐪嬪埌 mongodb 浣跨敤鐨勫唴瀛樹笉澶氾紙灝忎簬绱㈠紩鐨勫ぇ灝忥紝鐪嬫潵榪欐満鍣ㄤ笉瓚沖鏉ユ祴璇曪級銆?br /><br />鎹簡涓湁鍙敤 6G 鍐呭瓨鐨勬満鍣ㄣ傚湪 50 涓茍鍙戜笅錛屽彲浠ヨ揪鍒板鉤鍧?100 ms 宸﹀彸錛岀畻姣旇緝婊℃剰錛屼絾鏄茍鍙戝ソ鍍忚兘鍔涗笉澶熷己銆備絾榪欎釜鎬ц兘涓嶈兘鐢辨垜鎺у埗錛岃繕鐢辨満鍣ㄧ殑鍙敤鍐呭瓨鎺у埗銆傚師鍥犲氨鏄?mongodb 娌℃湁鎸囧畾鍙崰鐢ㄧ殑鍐呭瓨澶у皬錛屽畠鎶婃墍鏈夌┖闂插唴瀛樺綋緙撳瓨浣跨敤錛屾棦鏄紭鐐逛篃鏄己鐐癸細(xì)浼樼偣--鍙互鏈澶ч檺搴︽彁鍗囨ц兘錛涚己鐐?-瀹規(guī)槗鍙楀叾瀹冪▼搴忓共鎵幫紙鍗犵敤浜嗗畠鐨勭紦瀛橈級銆傜敱鎴戞祴璇曟潵鐪嬶紝瀹冩姠鍗犲唴瀛樼殑鑳藉姏涓嶅己銆俶ongodb 鏄敤鍐呭瓨鏄犲皠鏂囦歡 vmm錛屽畼鏂圭殑璇存槑錛?br /><br />Memory Mapped Storage Engine<br /><br />This is the current storage engine for MongoDB, and it uses memory-mapped files for all disk I/O. Using this strategy, the operating system's virtual memory manager is in charge of caching. This has several implications:<br /><br />There is no redundancy between file system cache and database cache: they are one and the same.<br />MongoDB can use all free memory on the server for cache space automatically without any configuration of a cache size.<br />Virtual memory size and resident size will appear to be very large for the mongod process. This is benign: virtual memory space will be just larger than the size of the datafiles open and mapped; resident size will vary depending on the amount of memory not used by other processes on the machine.<br />Caching behavior (such as LRU'ing out of pages, and laziness of page writes) is controlled by the operating system: quality of the VMM implementation will vary by OS.<br />鎵浠ヨ繖涔堟潵鐪嬶紝鎴戣寰?mongodb 娌℃湁鎸囧畾鍐呭瓨澶у皬鏉ヤ繚璇佹甯哥殑緙撳瓨鏄釜緙虹偣銆傚簲璇ヨ嚦灝戜繚璇佺儲(chǔ)寮曞叏閮ㄨ兘鏀懼埌鍐呭瓨涓備絾榪欎釜琛屼負(fù)涓嶆槸鐢卞惎鍔ㄧ▼搴忓喅瀹氾紝鑰屾槸鐢辯幆澧冨喅瀹氾紙緹庝腑涓嶈凍錛夈?br /><br />瀹樻柟涔熸湁孌靛唴瀹硅鍒扮儲(chǔ)寮曟斁鍒板唴瀛樹腑錛?br /><br />If your queries seem sluggish, you should verify that your indexes are small enough to fit in RAM. For instance, if you're running on 4GB RAM and you have 3GB of indexes, then your indexes probably aren't fitting in RAM. You may need to add RAM and/or verify that all the indexes you've created are actually being used.<br /><br />榪樻槸甯屾湜 mongodb 涓彲浠ユ寚瀹氬唴瀛樺ぇ灝忥紝紜繚瀹冩湁瓚沖鍐呭瓨鍔犺澆绱㈠紩銆?br /><br />灝忕粨錛氬ぇ鏁版嵁閲忎笅錛坘w綰э級mongodb 騫跺彂鏌ヨ涓嶅鐞嗘兂錛?00-200/s錛夈傚啓鏁版嵁寰堝揩錛堟垜鐨勭幆澧冿紝榪滅▼鎻愪氦榪?1w/s錛屼及璁¤揪鍒?1.5W/s 鏄病闂鐨勶紝鍩烘湰涓嶅彈澶ф暟鎹噺鐨勫獎(jiǎng)鍝嶏級銆?br /><br />璐翠釜嫻嬭瘯鏁版嵁錛?br /><br />1 id(鍐呭瓨浣跨敤 <1.5g) 10 id(鍐呭瓨浣跨敤 2-3g) 20 id(鍐呭瓨浣跨敤 >4g)<br />1 2 3 1 2 3 1 2 3<br />total time 17.136 25.508 17.387 37.138 33.788 25.143 44.75 31.167 30.678<br />1 thread thruput 583.5668 392.0339 575.1423 269.266 295.9631 397.725 223.4637 320.8522 325.9665<br />total time 24.405 22.664 24.115 41.454 41.889 39.749 56.138 53.713 54.666<br />5 thread thruput 2048.76 2206.142 2073.398 1206.156 1193.631 1257.893 890.6623 930.8733 914.6453<br />total time 27.567 26.867 28.349 55.672 54.347 50.93 72.978 81.857 75.925<br />10 thread thruput 3627.526 3722.038 3527.461 1796.235 1840.028 1963.479 1370.276 1221.643 1317.089<br />total time 51.397 57.446 53.81 119.386 118.015 76.405 188.962 188.034 138.839<br />20 thread thruput 3891.278 3481.53 3716.781 1675.238 1694.7 2617.63 1058.414 1063.637 1440.517<br />total time 160.038 160.808 160.346 343.559 352.732 460.678 610.907 609.986 1411.306<br />50 thread thruput 3124.258 3109.298 3118.257 1455.354 1417.507 1085.357 818.4552 819.6909 354.2818<br />total time 2165.408 635.887 592.958 1090.264 1034.057 1060.266 1432.296 1466.971 1475.061<br />100 thread thruput 461.8067 1572.606 1686.46 917.209 967.0647 943.1595 698.1797 681.6767 677.9381<br />涓婇潰鐨勬祴璇曞垎鍒敤涓夌鏌ヨ錛堟瘡嬈?1,10,20 id錛夛紝鍦ㄤ笉鍚屽茍鍙戜笅嫻嬭瘯3嬈★紝姣忔鍙戝嚭 1w 嬈℃煡璇€傜涓琛屾暟鎹負(fù)鎵鏈夌嚎紼嬬瘡鍔犳椂闂達(dá)紙鍗曚綅 ms錛夛紝絎簩琛屾暟鎹負(fù)鍚炲悙閲?1w /(total time / thread num))銆傛祴璇曚腑鍐呭瓨浣跨敤鎱㈡參澧炲姞錛屾墍浠ュ悗闈㈢殑鏁版嵁鍙兘姣旇緝楂樻晥鐨勶紙楂樻晥鐨勭幆澧冿級銆?br /><br />浠庝笂琛ㄧ湅錛?0 - 20綰跨▼姣旇緝楂樼殑鍚炲悙閲忋傜湅鍒板唴瀛樹嬌鐢紝鍓嶆彁灝辨槸绱㈠紩鍔犺澆鍒板唴瀛樹腑錛屽茍鏈変簺鍐呭瓨浣滀負(fù)緙撳瓨銆?br /><br />涓嬮潰鏈変釜绱㈠紩鏌ヨ浼樺寲鐨?pdf銆?br /><br />Indexing and Query Optimizer<br /><br />Indexing and Query Optimizer (Aaron Staple)<br />ps:<br /><br />榛樿 mongodb 鏈嶅姟鍣ㄥ彧鏈?0涓茍鍙戯紝濡傛灉瑕佹彁楂樺畠鐨勮繛鎺ユ暟錛屽彲浠ョ敤 --maxConns num 鏉ユ彁楂樺畠鐨勬帴鏀跺茍鍙戠殑鏁版嵁銆?br /><br />mongodb 鐨?java 椹卞姩榛樿鏈澶氬彧鏈?10 騫跺彂榪炴帴姹犮傝鎻愰珮瀹冿紝鍙互鍦?mongo.jar 鐨勭幆澧冧腑鍔犲叆 MONGO.POOLSIZE 緋葷粺鍙傛暟錛屽 java -DMONGO.POOLSIZE=50 ...<img src ="http://m.tkk7.com/paulwong/aggbug/422096.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/paulwong/" target="_blank">paulwong</a> 2015-01-06 23:39 <a href="http://m.tkk7.com/paulwong/archive/2015/01/06/422096.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>鍏充簬MongoDB鏈澶ц繛鎺ユ暟鐨勬煡鐪嬩笌淇敼http://m.tkk7.com/paulwong/archive/2015/01/06/422093.htmlpaulwongpaulwongTue, 06 Jan 2015 14:10:00 GMThttp://m.tkk7.com/paulwong/archive/2015/01/06/422093.htmlhttp://m.tkk7.com/paulwong/comments/422093.htmlhttp://m.tkk7.com/paulwong/archive/2015/01/06/422093.html#Feedback0http://m.tkk7.com/paulwong/comments/commentRss/422093.htmlhttp://m.tkk7.com/paulwong/services/trackbacks/422093.html
[root@DELL113 mongodb-linux-i686-2.4.1]# mongo admin -u root -p password
MongoDB shell version: 2.4.1
connecting to: 192.168.6.42/admin
> db.serverStatus().connections
{ "current" : 1, "available" : 818, "totalCreated" : NumberLong(1) }

閫斾腑available鏄劇ず818灝戜簡涓涓紝琛ㄧず絀洪棽鐨勩俢urrent琛ㄧず宸茬粡鍗犵敤浜嗙殑榪炴帴鏁幫紝涓ゆ暟涓鍔犲氨絳変簬819錛屽鏋滄垜鐜板湪鍦ㄨ繛鎺ヤ竴涓紝閭d箞available灝辨槸817錛宑urrent灝辨槸2

[root@DELL113 mongodb-linux-i686-2.4.1]# ./bin/mongo 192.168.6.42
MongoDB shell version: 2.4.1
connecting to: 192.168.6.42/test
> db.serverStatus().connections
"current" : 1, "available" : 818, "totalCreated" : NumberLong(1) }
> db.serverStatus().connections
"current" : 2, "available" : 817, "totalCreated" : NumberLong(2) }

819涓繛鎺ユ暟瀵逛簬涓鑸殑绔欑偣鎴戣涓哄凡緇忓鐢紝騫朵笖閮芥槸鐜拌繛鐜板彇鐜版柇銆備絾榪欎釜榪炴帴鏁頒篃鍙互淇敼錛屽彧瑕佸湪鍚姩鐨勬椂鍊欏姞鍏?-maxConns鍗沖彲
鏈嶅姟鍣ㄥ惎鍔?br />
[root@lee mongodb-linux-x86_64-2.4.1]# ./bin/mongod --dbpath=/root/db --maxConns=2000
Wed Apr 3 11:06:21.905 [initandlisten] MongoDB starting : pid=2812 port=27017 dbpath=/root/db 64-bit host=lee
Wed Apr 3 11:06:21.957 [initandlisten] db version v2.4.1
Wed Apr 3 11:06:21.957 [initandlisten] git version: 1560959e9ce11a693be8b4d0d160d633eee75110
Wed Apr 3 11:06:21.957 [initandlisten] build info: Linux ip-10-2-29-40 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_49
Wed Apr 3 11:06:21.957 [initandlisten] allocator: tcmalloc
Wed Apr 3 11:06:21.957 [initandlisten] options: { dbpath: "/root/db", maxConns: 2000 }
Wed Apr 3 11:06:21.982 [initandlisten] journal dir=/root/db/journal
Wed Apr 3 11:06:21.982 [initandlisten] recover : no journal files present, no recovery needed
Wed Apr 3 11:06:22.297 [initandlisten] preallocateIsFaster=true 2.62
Wed Apr 3 11:06:22.717 [initandlisten] --maxConns too high, can only handle 819
Wed Apr 3 11:06:22.724 [initandlisten] waiting for connections on port 27017
Wed Apr 3 11:06:22.725 [websvr] admin web console waiting for connections on port 28017
Wed Apr 3 11:06:25.126 [initandlisten] connection accepted from 192.168.4.86:53917 #1 (1 connection now open)

鏌ヨ鏈澶ц繛鎺ユ暟

[root@DELL113 mongodb-linux-i686-2.4.1]# ./bin/mongo 192.168.6.42
MongoDB shell version: 2.4.1
connecting to: 192.168.6.42/test
> db.serverStatus().connections
"current" : 1, "available" : 818, "totalCreated" : NumberLong(1) }

鍙戠幇榪樻槸819錛熷叾瀹炴槸Linux榛樿榪涚▼鑳芥墦寮鏈澶ф枃浠舵暟鏈夊叧錛屽彲浠ラ氳繃ulimit 瑙e喅

[root@lee mongodb-linux-x86_64-2.4.1]# ulimit -n 2500
[root@lee mongodb-linux-x86_64-2.4.1]# ./bin/mongod --dbpath=/root/db --maxConns=2000
Wed Apr 3 11:11:07.013 [initandlisten] MongoDB starting : pid=2930 port=27017 dbpath=/root/db 64-bit host=lee
Wed Apr 3 11:11:07.013 [initandlisten] db version v2.4.1
Wed Apr 3 11:11:07.013 [initandlisten] git version: 1560959e9ce11a693be8b4d0d160d633eee75110
Wed Apr 3 11:11:07.013 [initandlisten] build info: Linux ip-10-2-29-40 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_49
Wed Apr 3 11:11:07.013 [initandlisten] allocator: tcmalloc
Wed Apr 3 11:11:07.013 [initandlisten] options: { dbpath: "/root/db", maxConns: 2000 }
Wed Apr 3 11:11:07.031 [initandlisten] journal dir=/root/db/journal
Wed Apr 3 11:11:07.031 [initandlisten] recover : no journal files present, no recovery needed
Wed Apr 3 11:11:07.170 [initandlisten] waiting for connections on port 27017
Wed Apr 3 11:11:07.171 [websvr] admin web console waiting for connections on port 28017
Wed Apr 3 11:11:10.076 [initandlisten] connection accepted from 192.168.4.86:53161 #1 (1 connection now open)

鍐嶆煡鐪嬫渶澶ц繛鎺ユ暟錛屾悶瀹?br />
[root@DELL113 mongodb-linux-i686-2.4.1]# ./bin/mongo 192.168.6.42
MongoDB shell version: 2.4.1
connecting to: 192.168.6.42/test
> db.serverStatus().connections
"current" : 1, "available" : 1999, "totalCreated" : NumberLong(1) }

鍏充簬ulimit鐨勬洿澶氱煡璇嗗ぇ瀹跺彲浠ュ幓緗戜笂媯(gè)绱㈡绱?br />
瀹㈡埛绔▼搴忛氬父鏄氳繃DRIVER鏉ラ摼鎺ワ紝鐢變簬姣忔寤虹珛閾炬帴鐨勬垚鏈兘鎸洪珮錛屽洜姝ら兘鐢ㄩ摼鎺ユ睜鏉ュ疄鐜幫紝SPRING DATA MONGODB涓槸濡備笅閰嶇疆
mongo.dbname=cms
#綰跨▼姹犵殑澶у皬
mongo.connectionsPerHost=100
#榪欎釜*mongo.connectionsPerHost鍒欐槸濡傛灉閾炬帴鏁板ぇ浜?00鐨勭瓑寰厁ttk鏁?/span>
mongo.threadsAllowedToBlockForConnectionMultiplier=4
#絳夊緟綰跨▼鐨勭瓑寰呮椂闂?/span>
mongo.maxWaitTime=1500
mongo.socketTimeout=1500
mongo.connectTimeout=1000
mongo.autoConnectRetry=true
mongo.socketKeepAlive=true
mongo.slaveOk=true


  • autoConnectRetry simply means the driver will automatically attempt to reconnect to the server(s) after unexpected disconnects. In production environments you usually want this set to true.

  • connectionsPerHost are the amount of physical connections a single Mongo instance (it's singleton so you usually have one per application) can establish to a mongod/mongos process. At time of writing the java driver will establish this amount of connections eventually even if the actual query throughput is low (in order words you will see the "conn" statistic in mongostat rise until it hits this number per app server).

    There is no need to set this higher than 100 in most cases but this setting is one of those "test it and see" things. Do note that you will have to make sure you set this low enough so that the total amount of connections to your server do not exceed

    db.serverStatus().connections.available

    In production we currently have this at 40.

  • connectTimeout. As the name suggest number of milliseconds the driver will wait before a connection attempt is aborted. Set timeout to something long (15-30 seconds) unless there's a realistic, expected chance this will be in the way of otherwise succesful connection attempts. Normally if a connection attempt takes longer than a couple of seconds your network infrastructure isn't capable of high throughput.

  • maxWaitTime. Number of ms a thread will wait for a connection to become available on the connection pool, and raises an exception if this does not happen in time. Keep default.

  • socketTimeout. Standard socket timeout value. Set to 60 seconds (60000).

  • threadsAllowedToBlockForConnectionMultiplier. Multiplier for connectionsPerHost that denotes the number of threads that are allowed to wait for connections to become available if the pool is currently exhausted. This is the setting that will cause the "com.mongodb.DBPortPool$SemaphoresOut: Out of semaphores to get db connection" exception. It will throw this exception once this thread queue exceeds the threadsAllowedToBlockForConnectionMultiplier value. For example, if the connectionsPerHost is 10 and this value is 5 up to 50 threads can block before the aforementioned exception is thrown.

    If you expect big peaks in throughput that could cause large queues temporarily increase this value. We have it at 1500 at the moment for exactly that reason. If your query load consistently outpaces the server you should just improve your hardware/scaling situation accordingly.

  • readPreference(UPDATED, 2.8+) Used to determine the default read preference and replaces "slaveOk". Set up a ReadPreference through one of the class factory method. A full description of the most common settings can be found at the end of this post

  • w(UPDATED, 2.6+) This value determines the "safety" of the write. When this value is -1 the write will not report any errors regardless of network or database errors. WriteConcern.NONE is the appropriate predefined WriteConcern for this. If w is 0 then network errors will make the write fail but mongo errors will not. This is typically referred to as "fire and forget" writes and should be used when performance is more important than consistency and durability. Use WriteConcern.NORMAL for this mode.

    If you set w to 1 or higher the write is considered safe. Safe writes perform the write and follow it up by a request to the server to make sure the write succeeded or retrieve an error value if it did not (in other words, it sends a getLastError() command after you write). Note that until this getLastError() command is completed the connection is reserved. As a result of that and the additional command the throughput will be signficantly lower than writes with w <= 0. With a w value of exactly 1 MongoDB guarantees the write succeeded (or verifiably failed) on the instance you sent the write to.

    In the case of replica sets you can use higher values for w whcih tell MongoDB to send the write to at least "w" members of the replica set before returning (or more accurately, wait for the replication of your write to "w" members). You can also set w to the string "majority" which tells MongoDB to perform the write to the majority of replica set members (WriteConcern.MAJORITY). Typicall you should set this to 1 unless you need raw performance (-1 or 0) or replicated writes (>1). Values higher than 1 have a considerable impact on write throughput.

  • fsync. Durability option that forces mongo to flush to disk after each write when enabled. I've never had any durability issues related to a write backlog so we have this on false (the default) in production.

  • j *(NEW 2.7+)*. Boolean that when set to true forces MongoDB to wait for a successful journaling group commit before returning. If you have journaling enabled you can enable this for additional durability. Refer to http://www.mongodb.org/display/DOCS/Journaling to see what journaling gets you (and thus why you might want to enable this flag).

ReadPreference The ReadPreference class allows you to configure to what mongod instances queries are routed if you are working with replica sets. The following options are available :

  • ReadPreference.primary() : All reads go to the repset primary member only. Use this if you require all queries to return consistent (the most recently written) data. This is the default.

  • ReadPreference.primaryPreferred() : All reads go to the repset primary member if possible but may query secondary members if the primary node is not available. As such if the primary becomes unavailable reads become eventually consistent, but only if the primary is unavailable.

  • ReadPreference.secondary() : All reads go to secondary repset members and the primary member is used for writes only. Use this only if you can live with eventually consistent reads. Additional repset members can be used to scale up read performance although there are limits to the amount of (voting) members a repset can have.

  • ReadPreference.secondaryPreferred() : All reads go to secondary repset members if any of them are available. The primary member is used exclusively for writes unless all secondary members become unavailable. Other than the fallback to the primary member for reads this is the same as ReadPreference.secondary().

  • ReadPreference.nearest() : Reads go to the nearest repset member available to the database client. Use only if eventually consistent reads are acceptable. The nearest member is the member with the lowest latency between the client and the various repset members. Since busy members will eventually have higher latencies this should also automatically balance read load although in my experience secondary(Preferred) seems to do so better if member latencies are relatively consistent.

Note : All of the above have tag enabled versions of the same method which return TaggableReadPreference instances instead. A full description of replica set tags can be found here :Replica Set Tags



鍙傝冪綉鍧錛?br />http://api.mongodb.org/java/2.10.1/com/mongodb/MongoClientOptions.Builder.html#connectionsPerHost(int)
https://github.com/spring-projects/spring-data-mongodb/blob/master/spring-data-mongodb/src/main/resources/org/springframework/data/mongodb/config/spring-mongo-1.5.xsd

paulwong 2015-01-06 22:10 鍙戣〃璇勮
]]>
Architecture for Redis cache & Mongo for persistencehttp://m.tkk7.com/paulwong/archive/2015/01/04/422026.htmlpaulwongpaulwongSun, 04 Jan 2015 07:50:00 GMThttp://m.tkk7.com/paulwong/archive/2015/01/04/422026.htmlhttp://m.tkk7.com/paulwong/comments/422026.htmlhttp://m.tkk7.com/paulwong/archive/2015/01/04/422026.html#Feedback0http://m.tkk7.com/paulwong/comments/commentRss/422026.htmlhttp://m.tkk7.com/paulwong/services/trackbacks/422026.htmlhttp://www.javacodegeeks.com/2013/02/caching-with-spring-data-redis.html

Architecture for Redis cache & Mongo for persistence
http://stackoverflow.com/questions/11218941/architecture-for-redis-cache-mongo-for-persistence

MongoDB with redis
http://stackoverflow.com/questions/10696463/mongodb-with-redis/10721249#10721249

Caching Data in Spring Using Redis
http://caseyscarborough.com/blog/2014/12/18/caching-data-in-spring-using-redis/

Springside Redis
https://github.com/springside/springside4/wiki/Redis

Spring Cache娉ㄨВ+Redis
http://hanqunfeng.iteye.com/blog/2176172















paulwong 2015-01-04 15:50 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 中文字幕手机在线免费看电影| 亚洲欧洲另类春色校园网站| 精品国产亚洲AV麻豆| 精品国产免费观看| 日韩在线视精品在亚洲| 免费国产真实迷j在线观看| 又粗又长又爽又长黄免费视频| 免费中文字幕不卡视频| 一个人免费播放在线视频看片| 国产AV无码专区亚洲AWWW| 中文字幕不卡高清免费| 亚洲va中文字幕无码久久不卡| 日韩精品内射视频免费观看| 亚洲精品视频专区| 成人毛片18女人毛片免费视频未 | 国产亚洲AV夜间福利香蕉149 | 人人鲁免费播放视频人人香蕉| 中文字幕亚洲一区二区va在线| 免费a级毛片无码a∨免费软件| www在线观看免费视频| 自拍偷自拍亚洲精品被多人伦好爽| a级毛片黄免费a级毛片| 亚洲人成免费电影| 久久久久久成人毛片免费看| 亚洲黄色三级网站| 免费观看a级毛片| 国产福利免费视频 | 国产美女视频免费观看的网站 | 国产免费人人看大香伊| 国产免费A∨在线播放| 777亚洲精品乱码久久久久久| 妞干网免费观看视频| 国产免费久久久久久无码| 亚洲日本乱码一区二区在线二产线| 日本一区免费电影| 可以免费观看的国产视频| 亚洲色大成网站www尤物| 国产精品亚洲аv无码播放| 色窝窝免费一区二区三区| 香蕉免费一级视频在线观看| 亚洲人成小说网站色|