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

  • Home
  • SEARCH
  • 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 9128415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:30:30+00:00 2026-06-17T07:30:30+00:00

I have a query that needs to return a product and all its information

  • 0

I have a query that needs to return a product and all its information by its “_id” but when I print the results I get the cursor and not the values in the MongoDB collection?

var query_id = dbCollection.Find(Query.EQ("_id", "50ed4ea05baffd13a44d0154"));
return query_id.ToString();

The result is

MongoDB.Driver.MongoCursor`1[MongoDB.Bson.BsonDocument]

EDIT
I have tried the .ToJson() method but that only returns []

var query_id = dbCollection.Find(Query.EQ("_id", "50ed4ea05baffd13a44d0154"));
var r = query_id.ToJson();

EDIT
Here is the Code, its a basic Windows Form App that I am doing basic tests with:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        string connectionString = "mongodb://127.0.0.1";
        var server = MongoServer.Create(connectionString);

        if (server.State == MongoServerState.Disconnected)
        {
            server.Connect();
            label1.Text = ("Server is connected to: " + connectionString);
            button1.Enabled = false;
        }
        else
        {
            label1.Text = ("Server Error Check DB location");
        }

        var conn = server.GetDatabase("Acord");

        var dbCollection = conn.GetCollection("Mappings");

        var query = dbCollection.FindAll();
        //textBox2.Text = query.ToList().ToJson();

        var query_first = query.First();
        //textBox2.Text = cursorResult.ToString(); 

        var query_id = Query.EQ("_id", "1");//What ID do I put in here? This is were the error is now!
        var entity = dbCollection.FindOne(query_id);
        textBox2.Text = entity.ToString();
    }
}

Here is the error I get:

An unhandled exception of type 'System.NullReferenceException' occurred in WindowsFormsApplication1.exe

I am clearly missing something here?

  • 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-17T07:30:31+00:00Added an answer on June 17, 2026 at 7:30 am

    As you’ve noticed, Find() returns a cursor, which could be used to traverse the query results one-by-one. But you need only a single returned item, so use FindOne() – it will return you an item instead of a cursor.

    You should also use the correct query. E.g. By-Default MongoDB uses internal 12-bytes ObjectID, so Query.EQ("_id", "1") is simply wrong. If you are not sure about the query, call FindOne() without any arguments.

    I would recommend you trying the online MongoDB shell (at http://mongodb.org) which contains an interactive MongoDB tutorial.

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

Sidebar

Related Questions

I have a query such that I need to get A specific dog All
I have a query that will return results from 2 tables into 1 using
I have below a working query that needs to be simplified. The reason is
I have a result of a db query in java.sql.ResultSet that needs to be
I have a query that does what i want joining table but i need
Say I have a query that fetches [type][show_name]. For all [type]==5 records, I need
I have the following Sql Query that returns the type of results that I
I currently have a SQL query that returns a number of fields. I need
I have a query that I need to execute that I do not know
Using Microsoft SQL server 2008 I have a query that is in need of

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.