为什么Find方法超出MongDb C#驱动程序2.10.4的范围?

问题描述 投票:0回答:1

[嗨,我尝试在数据库中复制我的收藏集。我有以下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);
    }

以下课程是我的模特

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

对于我程序中的操作,我使用MongoCRUD类:

        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());

        }

    }

要测试功能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.

我不明白我需要指定范围吗?我需要创建一个批处理,因为集合很大?

有人可以向我解释为什么会发生这种情况以及我需要做些什么来正确复制我的收藏集。

谢谢您的时间。

[嗨,我尝试在数据库中复制我的收藏集。我将以下Main设置为白色:using MongoDB.Bson;使用MongoDB.Bson.Serialization.Attributes;使用MongoDB.Driver;使用系统;使用系统。...

c# mongodb mongodb-query mongodb-.net-driver
1个回答
0
投票

我发现尝试并出错后犯的错误。我的课程的类型不同于数据库中的数据。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.