現在、c#を使用してMongoDbにクエリを実行しているときに、Imに問題が発生しています。問題は、正しい結果または正しい数の結果が返されないということです。私は結果の正確な数を知らないが、それは100未満でなければならない。代わりに、私は350k-500kの結果を受け取っています(多くはnullです)。もう1つの問題は、プログラムが処理を完了するまでに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であるが、非常に大きな金額は次のとおりです。
あなたは何をしようとしていますか?説明していただけますか? – Saleem
この質問を使用して、文書またはそのサブ文書にpIDを持つすべての文書を取得しようとしています。サブ文書の名前は変わることはありませんが、文書の中にはサブ文書がありません。なぜ2つのクエリが必要なのでしょうか。 – CodePull