C#을 사용하여 MongoDb를 쿼리 할 때 현재 Im에 문제가 있습니다. 문제는 올바른 결과 또는 올바른 수의 결과가 반환되지 않는다는 것입니다. 결과의 정확한 수를 모르지만 100 미만이어야합니다. 대신, 나는 약 350k-500k 결과를 받는다 (많은 것은 null이다). 다른 문제는 프로그램이 처리를 끝내기까지 10 분 이상 소요된다는 것입니다.C# 쿼리에서 MongoDB가 올바른 결과를 반환하지 않음
다음과 같은 코드의 문제가있는 부분을 볼 수
public List<BsonDocument> find_All_Documents_With_pIDs()
{
List<string> databases = new List<string>();
List<BsonDocument> pDocs = new List<BsonDocument>();
databases.AddRange(mongo_Server.GetDatabaseNames());
//iterate through each db in mongo
foreach (string dbName in databases)
{
List<string> collections = new List<string>();
var database = mongo_Server.GetDatabase(dbName);
collections.AddRange(database.GetCollectionNames());
//iterate through each collection
foreach (string colName in collections)
{
var collection = database.GetCollection(colName);
//Iterate through each document
foreach (var document in collection.FindAllAs<BsonDocument>())
{
//Get all documents that have a pID in either the main document or its sub document
IMongoQuery query = Query.Exists(document.GetElement("_id").ToString().Remove(0,4) + ".pID");
IMongoQuery subQuery = Query.Exists(document.GetElement("_id").ToString() + ".SubDocument.pID");
pDocs.AddRange(collection.Find(query));
pDocs.AddRange(collection.Find(subQuery));
}
}
}
//Theres a collection used earlier in the program to backup the documents before processing. Not removing the documents from the list found in this location will result in duplicates.
return remove_Backup_Documents_From_List(pIDs);
}
어떤 도움에 감사드립니다!
편집 :
다음은 수신 된 데이터의 화면 캡처입니다. 다음하지만 매우 많은 양의이 같은 모든 데이터가 null :
스크립트가 먼저 데이터베이스collection.FindAllAs<BsonDocument>()
을에서 모든 문서를 가져오고 각에 대한 쿼리를 조립한다
무엇을하려고합니까? 설명해 주시겠습니까? – Saleem
이 쿼리를 사용하여 문서 또는 해당 하위 문서에 pID가있는 모든 문서를 가져 오려고합니다. 하위 문서의 이름은 절대로 변경되지 않지만 일부 문서에서는 하위 문서가 없으므로 두 개의 쿼리가 필요한 이유는 무엇입니까? – CodePull