1

Is there a way to implicitly exclude certain fields/types in some DB model in C#'s MongoDB, while still allowing to get them explicitly? for instance, I have a Model with two big lists:

public class Model {
    public string SomeName;
    public List<string> ManyManyStrings; // exclude implicitly?
    public List<ComplexType> VeryBigList; // exclude implicitly?
    public int SomeNumber;
    public byte[] LittleArrayOfBytes_NotBigDeal;
}

And when I call IMongoCollection<Model>.Find(SomeFilter), I have to explicitly exclude ManyManyStrings and VeryBigList:

var fastModel = modelCollection.Find(SomeFilter).Project<Model>(
    Builders<Model>.Projection
        .Exclude(m => m.ManyManyStrings)
        .Exclude(m => m.VeryBigList));

Yes, I can separate them to different types or different Collections and associate them via ObjectId or so...

But the model is so "right"! they just have to be there, logically... my Model has ManyManyStrings and VeryBigList, it's just so much pain to start linking between Models and lists of List<string> ManyManyStrings or List<ComplexType> VeryBigList in some other collections...

(btw, I don't think [BsonIgnore] will help here, as it prevents explicit retrieval as well. Or am I wrong? is there a way to "bypass" it?)

Tar
  • 8,529
  • 9
  • 56
  • 127
  • Is VeryBigList a growing list? And if it's the case, then I think it's time they should move to their own collection as every bson document has their own size limit. And BsonIgnore would essentially ignore them altogether in retrieval and insertion. I dont think there's a way that would allow you do it just one way. – Swagata Prateek Aug 20 '16 at 00:54

0 Answers0