jjzjj

BsonDocument

全部标签

c# - 我如何在 C# 的 mongodb 中通过 bsondocument 查询或查找

我有一个像这样的BsonDocument{"_id":"1db5b191-c6d5-47ea-90ef-98202f604a6b","_P21id":"#13","_EntityName":"IfcActorRole","Role":".SUPPLIER.","UserDefinedRole":"$","Description":"$"}如何通过这个BsonDocument查询{"_EntityName":"IfcActorRole","Role":".SUPPLIER.","UserDefinedRole":"$","Description":"$"} 最

c# - C# 中的 Mongodb $near 查询?

varquery="{'Geo':{'$near':{'$geometry':{'type':'Point','coordinates':[]}}}}";varparsing=BsonDocument.Parse(query);varqwithcoor=parsing["Geo"]["$near"]["$geometry"]["coordinates"].AsBsonArray;qwithcoor.AddRange(coordinates);parsing["Geo"]["$near"].AsBsonDocument.Add("$maxDistance",radius);varcoll

c# - 试图从我的 Mongo 数据库中的所有文档中获取单个字段的列表

我正在使用最后一个驱动程序。我的文档是这样的{"ItemID":292823,....}第一个问题:我正在尝试获取所有ItemID的列表,然后对它们进行排序。但是,我的搜索只是拉回所有_id,而没有拉回任何ItemID。我做错了什么?varf=Builders.Filter.Empty;varp=Builders.Projection.Include(x=>x["ItemID"]);varfound=collection.Find(f).Project(p).ToList().ToArray();当我尝试查询输出时,我得到以下信息。found[0].ToJson()"{\"_id\":

c# - 如何模拟 IMongoDatabase

我正在使用Moq在ASP.NETCore项目中模拟我的对象。我想模拟以下IsConnection()方法:publicClient(IMongoClientclient){_client=client;}publicasyncTaskIsConectionOk(){varpingCommand=newBsonDocument("ping",1);varmongoDb=_client.GetDatabase("Name");varcommandResult=awaitmongoDb.RunCommandAsync(pingCommand);returncommandResult!=nul

c# - Mongodb 聚合组然后条件总和使用 c#

我有一个包含以下示例数据的成员集合{"_id":ObjectId("50f6632d89862009f4c80e0f"),"_Ten":ObjectId("50f6632d89862009f4c80e0e"),"active":true,"role":"Administrator","_t":"User"}{"_id":ObjectId("50fe895678415503d022945f"),"_Ten":ObjectId("50f6632d89862009f4c80e0e"),"active":true,"role":"Contributor","_t":"User"}{"_id":

c# - 使用 C# 驱动程序在 mongodb 中查找计算值最高的文档

有没有办法在mongodb中找到计算值最高的文档?我有一个数组属性,它由int的1-5组成。我想找到均值最高的文档。像这样使用常规Linq:varentityWithCalculatedMax=collection.OrderByDescending(x=>x.Grade.Sum()/x.Grade.Count()).First();有什么建议吗?(我试图直接在数据库中执行此操作,因为我不想检索所有文档来获取文档) 最佳答案 不幸的是,这不能使用LINQ语法来完成。使用规范聚合语法更容易(也更具体),因为它记录在theofficia

c# - MongoDB C# 驱动程序 IAsyncCursor<BsonDocument> 行为?

我是MongoDB(及其dotnet核心C#驱动程序)的新手,我有以下关于IAsyncCursor行为的问题:来自官方文档:https://docs.mongodb.com/getting-started/csharp/query/,似乎推荐的遍历IAsyncCursor的方法是:varcollection=_database.GetCollection("restaurants");varfilter=newBsonDocument();varcount=0;using(varcursor=awaitcollection.FindAsync(filter)){while(awaitc

C# MongoDB 基于点数组的排名

正在研究最新的C#mongodb驱动程序和.NET4.5.1。我想在玩家之间进行一些定制的比赛。假设我有以下模型。publicsealedclassPlayerPoints{[BsonId]publicObjectIdPlayerId;publicDateTimeCreateDate;publicintPoints;publicint[]SeasonalPoints;}我希望能够获得特定SeasonalPoints索引之间的玩家排名。一个例子:{PlayerId:someId1,CreateDate:,Points:1000,SeasonalPoints:[100,100,100,10

java - 使用 Java MongoDb 驱动程序的 Bson pretty-print

我正在使用Mongo聚合框架,该框架使用JavaMongoDB驱动程序3.3版。我有一个聚合管道,它只是List类型的集合.我正在尝试找到一种方法来漂亮地打印管道的每个阶段。调用toString每个元素上的方法是不够的,因为每个阶段都是Bson的简单实现的一个实例接口(interface),即SimplePipelineStage.这个愚蠢的类没有任何重写toString方法。管道是使用mongojava驱动程序的工厂方法创建的Aggregates类,如下所示:Aggregates.match(/*...*/)Aggregates.project(/*...*/)//Andsoon..

c# - 将 BsonDocument 映射到类但出现错误

这是我从MongoDb集合中提取的BsonDocument。我想将其反序列化(或映射)到我在C#中创建的对象/类。{"_id":ObjectId("5699715218a323101c663b9a"),"type":null,"text":"Hellothisistext","user":{"hair":"brown","age":64}}这是我想将BsonDocument映射/反序列化到的类。类中的字段是我唯一想要检索的字段。publicclassMyType{publicBsonObjectId_id{get;set;}publicBsonStringtext{get;set;}}