Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strongly typed abstraction for ArrayFilters #10

Open
johnknoop opened this issue Mar 7, 2020 · 1 comment
Open

Strongly typed abstraction for ArrayFilters #10

johnknoop opened this issue Mar 7, 2020 · 1 comment

Comments

@johnknoop
Copy link
Owner

johnknoop commented Mar 7, 2020

repo.UpdateOneAsync(
  filter: show => show.Id == showId,
  update: upd => upd
    .Set(Builders<T>.ArrayFiltersReference
          .SelectArray(x => x.Seasons, "a")
          .ThenSelectArray("b", x => x.Episodes),
      DateTime.Today),
  options: new UpdateOptions {
    ArrayFilters = Builders<T>.ArrayFilters
      .AddFilter<Season>("a", season => season.Year == 2022)
      .AddFilter<Episode>("b", episode=> episode.Number == 5)
  }
)

// genererar reference:
"Seasons.$[a].Episodes.$[b].ReleaseDate"

// Genererar filter:
{
  "a.Year": { $eq: 2022 }
  "b.ReleaseDate": { $eq: 5 }
}
@johnknoop
Copy link
Owner Author

var filter = Builders<Channel>.Filter.Eq(x => x.Id, "5e4606e6ae7b090688671416");

var like = new Like() {Name = "new like", Id = "1"};
var episodeId = "5e46071d385a672b0cea0f86";
var trackId = "5e460dbe2bc5e70c9cfeac21";

var update = Builders<Channel>.Update.Push("Episodes.$[e].Tracks.$[t].Likes", like);

var arrayFilters = new List<ArrayFilterDefinition>();
ArrayFilterDefinition<BsonDocument> episodesFilter = new BsonDocument("e._id", new BsonDocument("$eq", episodeId));
ArrayFilterDefinition<BsonDocument> tracksFilter = new BsonDocument("t._id", new BsonDocument("$eq", trackId));
arrayFilters.Add(episodesFilter);
arrayFilters.Add(tracksFilter);

var updateOptions = new UpdateOptions { ArrayFilters = arrayFilters };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant