[CSHARP-4240] Feedback on Atlas Search Using C# Driver + Documents in BSON Created: 28/Jun/22  Updated: 06/Jan/23  Resolved: 06/Jan/23

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Angie Shaw Assignee: Unassigned
Resolution: Duplicate Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates CSHARP-4440 Incorporate MongoDB.Labs.Search library Closed
Quarter: FY23Q4

 Description   

Sharing feedback from client organization on Atlas Search using the C# driver:
 
For normal Finds and Aggregations, I can write idiomatic C# with a fluent builder API. I can use all the LINQ features I'm used to having on other data structures and database providers.For $search (and $searchMeta!)...I have to either # write the BSON as a string (and worry about escaping query strings properly)

  1. Create nested BsonDocument objects, which gets complicated and nasty very quickly. We ended up writing the helpers in this snippet (and more), which help but are still hard to read. And easy to get wrong if we mess up the structure of the object.

A normal find query, with all the type-safe "if it builds, it works" LINQ goodness:
// normal collection Find (where if it builds, it works)
collection
.Find(x => x.AnArrayField.Contains(someId))
.SortByDescending(x => x.ADateField)
.Project(x => new SomeModel(x.Id, x.Value1, x.Value2))
.ToList();
 
// Atlas Search stuff...where if it builds, we're still not sure it will work

// create text search operator with score boost
private BsonDocument SearchFieldWithBoost(string field, string value, int Boost)

{ return new("text", new BsonDocument("query", value) .AddRange(new BsonDocument("path", field)) .AddRange(new BsonDocument("score", new BsonDocument("boost", new BsonDocument("value", Boost) ))) ); }


// Add text search operator with fuzzy parameters
private BsonDocument GetTextFuzzyStage(string field, string value)

{ return new("text", new BsonDocument("query", value) .AddRange(new BsonDocument("path", field)) .AddRange(new BsonDocument("fuzzy", new BsonDocument("maxEdits", 2) .AddRange(new BsonDocument("prefixLength", 2)) ) ) ); }


// add numeric filter
private BsonDocument GetIntEqualsStage(string field, int value)

{ return new("range", new BsonDocument("path", field) .AddRange(new BsonDocument("gte", value)) .AddRange(new BsonDocument("lte", value)) ); }


// combine must, should, and filter arrays to build compound operator
private BsonDocument BuildCompoundStage(BsonArray should, BsonArray must, BsonArray filter)

{ var compoundStage = new BsonDocument(); if (must.Any()) compoundStage.AddRange(new BsonDocument("must", must)); if (should.Any()) compoundStage.AddRange(new BsonDocument("should", should)); if (filter.Any()) compoundStage.AddRange(new BsonDocument("filter", filter)); return new BsonDocument("compound", compoundStage); }

 
A basic user story the user offered is, "As a developer, I would like to use a fluent API and lambda expressions to build $search/$searchMeta aggregation stages that I can be confident are correctly written*.*i.e. only uses fields that are defined in my document model and only uses operators/options that are supported by Search with no typos."



 Comments   
Comment by James Kovacs [ 05/Jul/22 ]

Thank you for your feedback. We recently implemented $search support for our Java Driver in JAVA-4415. We would like to do the same for the .NET/C# Driver, but this work hasn't been prioritized yet. We will take your feedback into account during our next planning cycle. Please follow this ticket for updates on when we decide to implement this functionality.

Comment by Rachelle Palmer [ 04/Jul/22 ]

Moving to C# driver queue for review (and action, if any)

Comment by Elle Shwer [ 29/Jun/22 ]

btw rachelle.palmer@mongodb.com

Generated at Wed Feb 07 21:47:39 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.