Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7835277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:34:48+00:00 2026-06-02T13:34:48+00:00

Consider the following code var q = from e in myCollection.AsQueryable<Entity>() where e.Name ==

  • 0

Consider the following code

var q = from e in myCollection.AsQueryable<Entity>() where e.Name == "test" select e;

The actual query is very complex and I don’t like building it using QueryBuilder instead of LINQ.

So I want to convert it back to IMongoQuery to use in myCollection.Group() call since there is no GroupBy support through LINQ.

Is it possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T13:34:49+00:00Added an answer on June 2, 2026 at 1:34 pm

    Edited answer:

    I realized that there already is an official way to get the Mongo query from a LINQ query (I should have known!). You have to downcast the IQueryable<T> to a MongoQueryable<T> to get access to the GetMongoQuery method:

    var linqQuery = from e in collection.AsQueryable<Entity>() where e.Name == "test" select e;
    var mongoQuery = ((MongoQueryable<Entity>)linqQuery).GetMongoQuery();
    

    Original answer:

    At the moment there is no officially supported way to do that, but in the near future we do intend to make it easy to find out what MongoDB query the LINQ query was mapped to.

    In the short term you could use the following undocumented internal methods to find out what MongoDB query the LINQ query is mapped to:

    var linqQuery = from e in collection.AsQueryable<Entity>() where e.Name == "test" select e;
    var translatedQuery = (SelectQuery)MongoQueryTranslator.Translate(linqQuery);
    var mongoQuery = translatedQuery.BuildQuery();
    

    But at some point you might need to switch from these undocumented methods to officially supported methods (the undocumented methods might change or be renamed in the future).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following code: var Products_First = (from Entities.Product p in myContext.Product select p);
Consider the following code. var items = from i in context.Items select i; var
Consider following piece of code: declare @var bit = 0 select * from tableA
Consider the following C# code: IEnumerable numbers = Enumerable.Range(0, 10); var evens = from
Consider the following code: var sentences = [ 'Lorem ipsum dolor sit amet, consectetur
Please consider the following code and the explanation from this Mozilla tutorial Using web
I am trying to work with arrays in javascript. Consider the following code: var
Consider the following Javascript code: var a = []; var f = function() {
Consider the following piece of code. int var; cout << (long)&var; My doubt is
Consider The Following Actionscript/Flex code: var LC:LocalConnection=new LocalConnection(); LC.addEventListener(StatusEvent.STATUS, Status); LC.send('A', 'SomeMethodName', 'Message'); LC.send('B',

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.