2012-09-20 3 views
0

메타 데이터가 포함 된 설명 텍스트가있는 주석 컬렉션이 있습니다. 나는 Comment Text Array의 페이지 매김을 좋아한다. 페이지 매김을 통해 "이전 5"또는 "다음 5"를 얻을 수 있습니다. mongoDB에서 좋은 성능을 발휘하는 가장 좋은 방법은 무엇입니까?mongoDB 배열 페이지 매기기

{ "_id" : ObjectId("502c706ac2e6777781a593f6"), 
     "commentType":"loc", 
     "commentList" : [ 
{ "commentText" : "HelloComment", 
    "commentTS" : Date(1345165636344), 
    "commentLoc" : { "commentlat" : 0, 
    "commentlong" : 0 }, 
    "userInfo" : { "$ref" : "userProfile", 
    "$id" : ObjectId("4fd182d92b2a87f780c6bbe8") } }, 
{ "commentText" : "2222222", 
    "commentTS" : Date(1345165636344), 
    "commentLoc" : { "commentlat" : 0, 
    "commentlong" : 0 }, 
    "userInfo" : { "$ref" : "userProfile", 
    "$id" : ObjectId("4fd182d92b2a87f780c6bbe8") } }, 
{ "commentText" : "3333333", 
    "commentTS" : Date(1345165636344), 
    "commentLoc" : { "commentlat" : 0, 
    "commentlong" : 0 }, 
    "userInfo" : { "$ref" : "userProfile", 
    "$id" : ObjectId("4fd182d92b2a87f780c6bbe8") } }, 
{ "commentText" : "44444444", 
    "commentTS" : Date(1345165636344), 
    "commentLoc" : { "commentlat" : 0, 
    "commentlong" : 0 }, 
    "userInfo" : { "$ref" : "userProfile", 
    "$id" : ObjectId("4fd182d92b2a87f780c6bbe8") } }, 
{ "commentText" : "5555555", 
    "commentTS" : Date(1345165636344), 
    "commentLoc" : { "commentlat" : 0, 
    "commentlong" : 0 }, 
    "userInfo" : { "$ref" : "userProfile", 
    "$id" : ObjectId("4fd182d92b2a87f780c6bbe8") } }, 
{ "commentText" : "6666666", 
    "commentTS" : Date(1345165636344), 
    "commentLoc" : { "commentlat" : 0, 
    "commentlong" : 0 }, 
    "userInfo" : { "$ref" : "userProfile", 
    "$id" : ObjectId("4fd182d92b2a87f780c6bbe8") } }, 
    { "commentText" : "777777", 
    "commentTS" : Date(1345165636344), 
    "commentLoc" : { "commentlat" : 0, 
    "commentlong" : 0 }, 
    "userInfo" : { "$ref" : "userProfile", 
    "$id" : ObjectId("4fd182d92b2a87f780c6bbe8") } }, 
    { "commentText" : "888888", 
    "commentTS" : Date(1345165636344), 
    "commentLoc" : { "commentlat" : 0, 
    "commentlong" : 0 }, 
    "userInfo" : { "$ref" : "userProfile", 
    "$id" : ObjectId("4fd182d92b2a87f780c6bbe8") } }, 
    { "commentText" : "6666666", 
    "commentTS" : Date(1345165636344), 
    "commentLoc" : { "commentlat" : 0, 
    "commentlong" : 0 }, 
    "userInfo" : { "$ref" : "userProfile", 
    "$id" : ObjectId("4fd182d92b2a87f780c6bbe8") } }, 
{ "commentText" : "999999", 
    "commentTS" : Date(1345165668809), 
    "commentLoc" : { "commentlat" : 0, 
    "commentlong" : 0 }, 
    "userInfo" : { "$ref" : "userProfile", 
    "$id" : ObjectId("4fdeb271de26fd298262bb84") } }, 
{ "commentText" : "HelloComment", 
    "commentTS" : Date(1345749858601), 
    "commentLoc" : { "commentlat" : 0, 
    "commentlong" : 0 }, 
    "userInfo" : { "$ref" : "userProfile", 
    "$id" : ObjectId("4fdeb271de26fd298262bb84") } }, 
{ "commentText" : "NewTestforcomments", 
    "commentTS" : Date(1345750020526), 
    "commentLoc" : { "commentlat" : 0, 
    "commentlong" : 0 }, 
    "userInfo" : { "$ref" : "userProfile", 
    "$id" : ObjectId("4fdeb271de26fd298262bb84") } } ], 
    } } 

도움 주셔서 감사합니다.

답변

4

당신은 $slice으로이 작업을 수행 할 수 있습니다 http://www.mongodb.org/display/DOCS/Retrieving+a+Subset+of+Fields#RetrievingaSubsetofFields-RetrievingaSubrangeofArrayElements

, 여기 또한 슬라이스의 JS 테스트 예를 들어있어 몇 가지 예제 : https://github.com/mongodb/mongo/blob/master/jstests/slice1.js

그래서, $slice와 함께 findOne은 아마 길을 가야하는 것입니다 .

사용중인 언어에 대한 정보가 없으면 내가 할 수있는 가장 깊은 것 같아요.

+0

응답 해 주셔서 감사합니다. $ slice 나를 위해 작동합니다. – atandon