[CSHARP-1701] how we can use $where from c# driver Created: 11/Jul/16  Updated: 11/Jul/16  Resolved: 11/Jul/16

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

Type: New Feature Priority: Minor - P4
Reporter: Greg Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

generic


Issue Links:
Duplicate
duplicates CSHARP-1445 Support arbitrary filters in the LIN... Closed

 Description   

When using syntax

var result = _collection.AsQueryable().Where(x => x.FSTicker == x.Sedol).ToList();

I'm getting exception:

Result Message: System.ArgumentException : Unsupported filter: (

{document}{fstick} == {document} {sedol}).

Is there a way to us $where from c# code?
Now I'm using aggregation as a workaround.


full stack trace:

Test Name: Comparison
Test FullName: SoQuestionsSolver.CompareOnSameDocumentFieldsFeature.Comparison
Test Source: C:\Users\gbernas\Source\Repos\profesor79\SoQuestionsSolver\SoQuestionsSolver\CompareOnSameDocumentFields.feature : line 5
Test Outcome: Failed
Test Duration: 0:00:00.497

Result StackTrace:
at MongoDB.Driver.Linq.Translators.PredicateTranslator.Translate(Expression node)
at MongoDB.Driver.Linq.Translators.PredicateTranslator.Translate(Expression node, IBsonSerializerRegistry serializerRegistry)
at MongoDB.Driver.Linq.Translators.QueryableTranslator.TranslateWhere(WhereExpression node)
at MongoDB.Driver.Linq.Translators.QueryableTranslator.Translate(Expression node)
at MongoDB.Driver.Linq.Translators.QueryableTranslator.TranslatePipeline(PipelineExpression node)
at MongoDB.Driver.Linq.Translators.QueryableTranslator.Translate(Expression node)
at MongoDB.Driver.Linq.Translators.QueryableTranslator.Translate(Expression node, IBsonSerializerRegistry serializerRegistry)
at MongoDB.Driver.Linq.MongoQueryProviderImpl`1.Translate(Expression expression)
at MongoDB.Driver.Linq.MongoQueryProviderImpl`1.GetExecutionModel(Expression expression)
at MongoDB.Driver.Linq.MongoQueryableImpl`2.ToCursor(CancellationToken cancellationToken)
at MongoDB.Driver.IAsyncCursorSourceExtensions.ToList[TDocument](IAsyncCursorSource`1 source, CancellationToken cancellationToken)
at SoQuestionsSolver.CompareOnSameDocumentFieldsSteps.ThenTryToUseWhereClause() in C:\Users\gbernas\Source\Repos\profesor79\SoQuestionsSolver\SoQuestionsSolver\CompareOnSameDocumentFieldsSteps.cs:line 46
at lambda_method(Closure , IContextManager )
at TechTalk.SpecFlow.Bindings.BindingInvoker.InvokeBinding(IBinding binding, IContextManager contextManager, Object[] arguments, ITestTracer testTracer, TimeSpan& duration)
at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStepMatch(BindingMatch match, Object[] arguments)
at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStep(StepInstance stepInstance)
at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnAfterLastStep()
at TechTalk.SpecFlow.TestRunner.CollectScenarioErrors()
at SoQuestionsSolver.CompareOnSameDocumentFieldsFeature.ScenarioCleanup()
at SoQuestionsSolver.CompareOnSameDocumentFieldsFeature.Comparison() in C:\Users\gbernas\Source\Repos\profesor79\SoQuestionsSolver\SoQuestionsSolver\CompareOnSameDocumentFields.feature:line 8
Result Message: System.ArgumentException : Unsupported filter: ({document}{fstick} == {document}{sedol}

).



 Comments   
Comment by Greg [ 11/Jul/16 ]

Thanks Craig!

Comment by Craig Wilson [ 11/Jul/16 ]

I've linked a duplicate request.

Note that this isn't supported because MongoDB's query language doesn't support field-to-field comparisons. Regardless, I'd highly suggest not using $where. It requires falling back to javascript, which is slow. Your "workaround" using aggregation is a much better way to go.

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