3

I have two classes:

public class Client
{
    [BsonId]
    public string Id { get; set; }
    public ICollection<OtherData> Other { get; set; }

}

and

public class OtherData
{
    [BsonId]
    public string Id { get; set; }
    public string Text { get; set; }
}

I have a collection of documents of Client.

I'd like to update a item on Other based on it's id. So I have this code.

Expression<Func<Client, bool>> filter = x =>
            x.Id == id
            && x.Other.Any(t => t.Id == idOther);

var update = new UpdateDefinitionBuilder<Client>()
            .Set(x => x.Other.ElementAt(-1), dadoBancario);

await _collection.FindOneAndUpdateAsync(filter, update);

But when I run this code, I get this error:

Command findAndModify failed: The dollar ($) prefixed field 'Other.$' in 'Other.$' is not valid for storage.. MongoDB.Driver.MongoCommandException at MongoDB.Driver.Core.WireProtocol.CommandWireProtocol1.ProcessReply(ConnectionId connectionId, ReplyMessage1 reply)

I'm using Cosmos DB. Is this some compatibillity issue?

Or there is another way that I can go?

ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
Jedi31
  • 735
  • 1
  • 6
  • 22
  • 1
    `x.Other.ElementAt(-1)` does not look right to me. I'd expect this to throw an `ArgumentOutOfRangeException` in Linq2Objects, and be shocked if a Linq2Sql implementation allowed it. – Jonathon Chase Sep 05 '18 at 01:24
  • It does not. The driver converts to mongodb dialect correct. In fact, cosmo db api still does not support it. It's a duplicate question. – Jedi31 Sep 05 '18 at 20:48

0 Answers0