복붙노트

[MONGODB] 어떻게 효율적으로 MongoDB에 관련된 문제를 해결하기 위해? [닫은]

MONGODB

어떻게 효율적으로 MongoDB에 관련된 문제를 해결하기 위해? [닫은]

이 다른 문제에 대한 MongoDB의 태그에 많은 질문이고, 또한 유사한 데이터를 요청하는 의견의 일부 무리가 있음을 참조하십시오.

그래서 좋은 질문을하지만,이 MongoDB를 관련이없는 방법을 제공합니다. 나에게 좋은 가치있는 질문을 할 수 있도록 좋은 문서가 있습니까?

해결법

  1. ==============================

    1.MongoDB의 관련 질문에 대한 좋은 가치 답을 여기에 도움이 될 것입니다 몇 가지 규칙이있다.

    MongoDB의 관련 질문에 대한 좋은 가치 답을 여기에 도움이 될 것입니다 몇 가지 규칙이있다.

    빨리 좋은 답을 찾을하는 데 도움이 수있는 데이터를 수집하는 데 도움이 될 몇 가지 일반적인 범주와 단계는 아래를 참조하시기 바랍니다.

    RE : 1

    윈도우 노트북에 몽고 2.6을 사용하여 내가 2GB 이하 수집 큰을 드릴 수 없습니다, 그 이유는 무엇입니까?

    RE : 2

    내 쿼리 db.collection.find ({isValid : 사실은}) 30 초 이상 걸리면, 출력을 설명 참조하십시오

    {
        "queryPlanner" : {
            "plannerVersion" : 1,
            "namespace" : "test.collectionName",
            "indexFilterSet" : false,
            "parsedQuery" : {},
            "winningPlan" : {
                "stage" : "COLLSCAN",
                "direction" : "forward"
            },
            "rejectedPlans" : []
        },
        "executionStats" : {
            "executionSuccess" : true,
            "nReturned" : 6,
            "executionTimeMillis" : 0,
            "totalKeysExamined" : 0,
            "totalDocsExamined" : 6,
            "executionStages" : {
                "stage" : "COLLSCAN",
                "nReturned" : 6,
                "executionTimeMillisEstimate" : 0,
                "works" : 8,
                "advanced" : 6,
                "needTime" : 1,
                "needYield" : 0,
                "saveState" : 0,
                "restoreState" : 0,
                "isEOF" : 1,
                "invalidates" : 0,
                "direction" : "forward",
                "docsExamined" : 6
            }
        },
        "serverInfo" : {
            "host" : "greg",
            "port" : 27017,
            "version" : "3.3.6-229-ge533634",
            "gitVersion" : "e533634d86aae9385d9bdd94e15d992c4c8de622"
        },
        "ok" : 1.0
    }
    

    RE : 3

    내 통합 파이프 라인의 모든 기록에서 지난 3 개 배열 요소를 얻을하는 데 문제가, 3.2.3 몽고

    내 쿼리 db.collection.aggregate ([{집계 파이프 라인}])

    문서 스키마

    {
        "_id" : "john",
        "items" : [{
                "name" : "John",
                "items" : [{
                        "school" : ObjectId("56de35ab520fc05b2fa3d5e4"),
                        "grad" : true
                    }
                ]
            }, {
                "name" : "John",
                "items" : [{
                        "school" : ObjectId("56de35ab520fc05b2fa3d5e5"),
                        "grad" : true
                    }
                ]
            }, {
                "name" : "John",
                "items" : [{
                        "school" : ObjectId("56de35ab520fc05b2fa3d5e6"),
                        "grad" : true
                    }
                ]
            }, {
                "name" : "John",
                "items" : [{
                        "school" : ObjectId("56de35ab520fc05b2fa3d5e7"),
                        "grad" : true
                    }
                ]
            }, {
                "name" : "John",
                "items" : [{
                        "school" : ObjectId("56de35ab520fc05b2fa3d5e8"),
                        "grad" : true
                    }
                ]
            }
        ]
    }
    
    //expected result
    
    {
        "_id" : "john",
        "items" : [{
                "name" : "John",
                "items" : [{
                        "school" : ObjectId("56de35ab520fc05b2fa3d5e4"),
                        "grad" : true
                    }
                ]
            }, {
                "name" : "John",
                "items" : [{
                        "school" : ObjectId("56de35ab520fc05b2fa3d5e5"),
                        "grad" : true
                    }
                ]
            }, {
                "name" : "John",
                "items" : [{
                        "school" : ObjectId("56de35ab520fc05b2fa3d5e6"),
                        "grad" : true
                    }
                ]
            }
        ]
    }
    

    RE : 4

    내 복제 세트에 문제가 데이터가 rs.config 덤프 아래 몽고 3.2을 사용하여 다른 서버에 복제되지 않습니다 있습니다 :

       {
           "_id" : "rs0",
           "version" : 1,
           "members" : [
              {
                 "_id" : 1,
                 "host" : "mongodb0.example.net:27017"
              }
           ]
        }
    

    RE : 5

    나는 집계 쿼리에 몽고와 문제가 C #을 드라이버에서 결과를 입력 가야

    startDate = new Date() // Current date
    startDate.setDate(startDate.getDate() - 7) // Subtract 7 days
    
    db.collection.aggregate([{
                $match : {
                    LastUpdate : {
                        $gte : startDate
                    }
                }
            }, {
                $sort : {
                    LastUpdate : -1
                }
            }, //sort data
            {
                $group : {
                    _id : "$Emp_ID",
                    documents : {
                        $push : "$$ROOT"
                    }
                }
            }, {
                $project : {
                    _id : 1,
                    documents : {
                        $slice : ["$documents", 3]
                    }
                }
            }
        ])
    

    내 C # 코드

    public static void Main()
    {
        var client = new MongoClient("mongodb://localhost:27017");
        var database = client.GetDatabase("test");
    
        var collection = database.GetCollection<InnerDocument>("irpunch");
    
    
        var aggregationDocument = collection.Aggregate()
            .Match(x=>x.LastUpdate> DateTime.Now.AddDays(-40))
            .SortByDescending(x => x.LastUpdate)
            .Group(BsonDocument.Parse("{ _id:'$Emp_ID', documents:{ '$push':'$$ROOT'}}"))
            // how to get projection result as typed object ??
            .Project(BsonDocument.Parse("{ _id:1, documents:{ $slice:['$documents', 3]}}")).ToList();
    
    
        }
    }
    
  2. from https://stackoverflow.com/questions/37932924/how-to-solve-mongodb-related-issue-efficiently by cc-by-sa and MIT license