0

Hi I upgrade my mongodb driver to 2.2.3.3 version and I want to use SelectMany operator to query nested document.But when I try to execute my query I get "The SelectMany query operator is not supported error". Here is my code:

MongoDatabase database;
var client = new MongoClient("mongodb://myconnection");
var server = client.GetServer();
database = server.GetDatabase("MyDB");
MongoCollection<DGTable> collection;
collection = database
    .GetCollection<DGTable>(typeof(DGTable).Name);

var result = collection.AsQueryable()
    .SelectMany(p => p.TableColumns);
var abc = result.ToList();
2
  • 1
    If the error says "not supported," doesn't that tell you what the problem is? What is your question? Commented Apr 15, 2016 at 12:50
  • As I know latest version 2.2.3.3 mongodb c# driver support SelectMany ability,and I want to understand ,Do I wrong useage of SelectMany or may be I have to do different things to use SelectMany. Commented Apr 15, 2016 at 14:23

2 Answers 2

1

You can postpone the call to .SelectMany(...) until after you have the data. The method call doesn't increase the amount of data or does some db-specific-performance operation, so there is no explicit reason to call it within the query.

var result = collection.AsQueryable()
    .Select(p => p.TableColumns)
    .ToList();
var abc = result
    .SelectMany(p => p)
    .ToList();
Sign up to request clarification or add additional context in comments.

Comments

0

I find solution,I have some obsolute methods and I upgrade my code to new methods then it works

      var client = new MongoClient("mongodb://myconnection");

        var db = client.GetDatabase("mydb");
        var col = db.GetCollection<DGTable>("DGTable");

        var sadsdadas = col.AsQueryable().SelectMany(p => p.TableColumns).ToList();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.