[SERVER-56162] BsonRepresentation(BsonType.String) can't support aggregate mongoDB Created: 19/Apr/21  Updated: 06/Dec/22  Resolved: 22/Apr/21

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Inbar Kabala Assignee: Backlog - Triage Team
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Server Triage
Operating System: ALL
Steps To Reproduce:

using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Driver;
using MongoDB.Driver.Linq;
using System;
using System.Linq;

namespace ConsoleApp3
{
class Program
{
static void Main(string[] args)

{ var dbc = new MongoDbCTX(); dbc.Samples.InsertOne(new Sample() \{ TID = "1", UID = "1", CTX = "11", STAT = Status.B }

);
dbc.Samples.InsertOne(new Sample() { TID = "1", UID = "2", CTX = "11", STAT = Status.B });
dbc.Samples.InsertOne(new Sample() { TID = "1", UID = "3", CTX = "11", STAT = Status.C });
dbc.Samples.InsertOne(new Sample() { TID = "1", UID = "4", CTX = "22", STAT = Status.B });
dbc.Samples.InsertOne(new Sample() { TID = "1", UID = "5", CTX = "22", STAT = Status.C });

var x = dbc.Samples.Aggregate()
.Match(x=>x.TID == "1")
.Group(
doc => doc.CTX,
group => new

{ C = group.Key, B = group.Where(x => x.STAT == Status.B).Count(), C = group.Where(x => x.STAT == Status.C).Count(), }

).ToList();

}
}
public class MongoDbCTX
{
private readonly IMongoClient _mongoDbClient = null;
private readonly IMongoDatabase _mongoDb = null;
public IMongoCollection<Sample> Samples => _mongoDb.GetCollection<Sample>(nameof(Samples));
public MongoDbCTX()

{ _mongoDbClient = new MongoClient("mongodb://localhost"); _mongoDb = _mongoDbClient.GetDatabase("test"); }

public IAggregateFluent<TDocument> Aggregate<TDocument>() =>
_mongoDb.GetCollection<TDocument>(nameof(TDocument)).Aggregate();

}
public class Sample

{ [BsonId] public string ID => $"\{TID} {UID}

{CTX}";
public string UID { get; set; }
public string TID { get; set; }
public string CTX { get; set; }
[BsonRepresentation(BsonType.String)] // if disabled it works
public Status STAT { get; set; } = Status.A;
}
public enum Status

{ A, B, C, }

}

Participants:

 Description   

Hi 

I try to use [BsonRepresentation(BsonType.String)] with Aggregate()
but it's not working, in case I'm disable this , it's working.

can you help please?

thanks,

Inbar 
 



 Comments   
Comment by Edwin Zhou [ 22/Apr/21 ]

Hi inbar.kabala@hp.com,

Thanks for your report. Please note that the SERVER project is for bugs and feature suggestions for the MongoDB server. As this ticket does not appear to be a bug, I will now close it. If you need further assistance troubleshooting, I encourage you to ask our community by posting on the MongoDB Developer Community Forums.

Kind regards,
Edwin

Generated at Thu Feb 08 05:38:31 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.