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 4580942
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:51:14+00:00 2026-05-21T20:51:14+00:00

I have a MongoDB collection called employees where there are documents like this: {

  • 0

I have a MongoDB collection called “employees” where there are documents like this:

{ 
  "_id": "4dc077b07701540f34000001", 
  "FullName": "Fullname...", 
  "FirstName": "First name...", 
  "LastName": "Last name...", 
  "Title": "Title... ",
  "Location": "Location...", 
  "Customer": "Customer...", 
  "Phone": "Phone...", 
  "CellPhone" : "Cellphone...", 
  "EMail": "E-mail..." 
}

I am trying to make a method that does a foreach loop on all documents in the collection and puts each value of the FullName-key and adds it to a List.

        List<string> listed = new List<string>();
        IMongoCollection collection = _db.GetCollection("employees");
        //var list = collection.FindAll().Documents.ToList();
        var persons = from p in collection.AsQueryable()
                      select p["FullName"];
        //foreach (var lt in list)
        foreach (var name in persons)
        {
            //listed.Add(lt["FullName"].ToString());
            listed.Add(name.ToString());
        }
        return listed;

Above is the code I have tried, the commented-code returns a NullReferenceException, the uncommented code returns the whole document in a list.

My question is: What kind of query must I do to get each value for every key called “FullName” into a list? I am using the current MongoDB stable version on Windows 7, and I am using the MongoDB-CSharp community driver. All help and pointers are appreciated!

  • 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-05-21T20:51:15+00:00Added an answer on May 21, 2026 at 8:51 pm
    var collection = _db.GetCollection("employees");
    return (from p in collection.AsQueryable()
             select p["FullName"]).toList();
    

    Should do it?

    However you should consider using the generic methods as seen in:

    http://www.mongodb.org/display/DOCS/CSharp+Driver+Tutorial#CSharpDriverTutorial-GetCollectionmethod

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

Sidebar

Related Questions

i have a mongoDB collection named col that has documents that look like this
I have 10000 documents in one MongoDB collection. I'd like to update all the
I have a large collection (~2.7 million documents) in mongodb, and there are a
In MongoDB I have a collection of documents called 'clients', where each document is
I have several documents in a MongoDB Collection, with a field 'name' (which is
I have a MongoDB Collection called Questions which holds JSON Objects that look like
I have a MongoDB collection with documents in the following format: { _id :
I have mongodb running and using morphia. Having a Collection of BatchData Documents and
Let's assume that I have a collection in mongodb, where all of its documents
I have a php script that looks like this: $contacts[{$firstname}] = $_POST[{$firstname}] ; $contacts[{$lastname}]

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.