簡體   English   中英

為什么 Find 方法超出范圍 MongDb C# 驅動程序 2.10.4?

[英]Why Find method get out of range MongDb C# driver 2.10.4?

嗨,我嘗試在數據庫中復制我的收藏。 我有白色以下Main

using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Driver;
using System;
using System.Collections.Generic;


static void Main(string[] args)
    {
        MongoCRUD db = new MongoCRUD("testClass");


        /* copy the colection*/
        var targetTable = "geo2";
        var newTable = "NormalizeCordinatesGeo";

        db.CopyColection<GlobalUrbanPoint>(targetTable, newTable);
    }

下面的 class 是給我的 model

public class GlobalUrbanPoint 
    {
        [BsonId]
        public ObjectId  Id{ get; set; }
        public double LATITUDE { get; set; } 
        public double LONGITUDE { get; set; } 
        ...
    }

對於我程序中的操作,我使用MongoCRUD class:

        public class MongoCRUD
    {
        private IMongoDatabase db;

        public MongoCRUD(string database)
        {
            var client = new MongoClient();
            db = client.GetDatabase(database);
        }

        ...

        public void CopyColection<T>(string targetTable, string newTable)
        {
            var source_colection = db.GetCollection<T>(targetTable);
            var dest = db.GetCollection<T>(newTable);
            dest.InsertMany(source_colection.Find(new BsonDocument()).ToList());

        }

    }

為了測試 function CopyColection我有一個包含 6 個文檔的托管箱,它按預期工作。 當我嘗試使用 66.579 個文檔復制更具體的更大集合時,出現流動錯誤

System.FormatException: An error occurred while deserializing the TYPE property of class MongoDBCurve.Program+GlobalUrbanPoint: Index was outside the bounds of the array.

我不明白我需要指定界限嗎? 我需要創建一個批次,因為集合太大了?

有人可以向我解釋為什么會發生這種情況以及我需要做什么才能正確復制我的收藏。

感謝您的時間。

我發現我在嘗試和錯誤后犯的錯誤。 我的 class 的字段類型與數據庫中的數據不同。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM