如何在不指定类的情况下使用MongoDB C#驱动程序

路加福音101

我正在使用MongoDB c#驱动程序2.0。我试图在不指定类型或类的情况下获取集合。观察:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Driver.Core;
using MongoDB.Driver.Linq;
using MongoDB.Shared;

namespace Meshplex.Service.DataWarehouse
{
    public class ProfileControllerMongoDB
    {
        private IMongoDatabase _mongoDb;
        private IMongoCollection _myCollection;
        //private IMongoCollection<ClassHere> _myCollection;

        public ProfileDataControllerMongoDB()
        {
            _mongoDb = GetMongoDatabase();
            _myCollection = _mongoDb.GetCollection(GetCollectionName());
            //_myCollection = _mongoDb.GetCollection<ClassHere>("Collection");
        }

        public async Task<string> GetAllRecords()
        {
            //This should return json
            return await _myCollection.Find(new BsonDocument());
        }

如您所见,我应该在声明时指定一个类IMongoCollection有没有一种方法可以使用MongoDB驱动程序而不指定类?

罗恩·拜尔

MongoDbdynamic在通用参数中支持一种类型。

IMongoCollection<dynamic> _myCollection = _mongoDb.GetCollection<ClassHere>("Collection");

参见http://mongodb.github.io/mongo-csharp-driver/2.0/what_is_new/#new-api

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

MongoDB C#驱动程序超时

来自分类Dev

如何使用MongoDB C#驱动程序进行$ lookup?

来自分类Dev

如何使用MongoDB C#驱动程序聚合$ lookup?

来自分类Dev

GroupBy Mongodb使用驱动程序C#

来自分类Dev

使用MongoDB C#驱动程序查询数组的数组

来自分类Dev

使用C#驱动程序从mongodb查询标签

来自分类Dev

使用MongoDB C#驱动程序进行存储桶

来自分类Dev

如何在不弹出设备的情况下使用Realtek驱动程序访问耳机模式?

来自分类Dev

MongoDB全文搜索C#驱动程序

来自分类Dev

MongoDB C#驱动程序连接池

来自分类Dev

MongoDB C#驱动程序MongoCredential对象

来自分类Dev

Mongodb C#驱动程序和ISODate

来自分类Dev

在MongoDB C#驱动程序中获取生成的脚本

来自分类Dev

检查插入是否成功(MongoDB C#驱动程序)

来自分类Dev

从2.0 MongoDb C#驱动程序获取结果

来自分类Dev

MongoDb与查询C#驱动程序不同

来自分类Dev

mongodb C#驱动程序更新多个字段

来自分类Dev

MongoDB C#驱动程序字段投影

来自分类Dev

MongoDB C#驱动程序和DateTime字段

来自分类Dev

C#驱动程序2.0 Mongodb UpdateOneAsync

来自分类Dev

MongoDB C#驱动程序2.1.0-解决参考

来自分类Dev

MongoDB C#驱动程序和DateTime字段

来自分类Dev

Mongodb C#驱动程序Linq查询分组依据

来自分类Dev

MongoDB C#官方驱动程序批量更新

来自分类Dev

MongoDB C#驱动程序2.0查询样式

来自分类Dev

MongoDb C#驱动程序2.0多对多

来自分类Dev

MongoDB C#驱动程序无法识别某些类型

来自分类Dev

MongoDB聚合查询通过C#驱动程序变慢

来自分类Dev

使用 C# 驱动程序序列化 BsonArray