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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:12:08+00:00 2026-06-15T11:12:08+00:00

I have a complete dictionary of some 236000 words. I inserted all words from

  • 0

I have a complete dictionary of some 236000 words.

I inserted all words from the text file into and SQL server DB and a MongoDb ensuring an index on both DB’s on the the word field.

I loop through all mongo documents inserting each word into a Dictionary in C#
It takes 2.5 seconds. Sometimes slightly less sometimes slightly more.

I loop through all words in a text file inserting them into Dictionary in C#
It takes 0.9 seconds. Sometimes slightly less sometimes slightly more.

I loop through all words in the SQL DB inserting words into a Dictionary in C#
It takes 1.1 seconds. Sometimes slightly less sometimes slightly more.

Should MongoDB be quicker?

MongoDB:

var connectionString = "mongodb://localhost";
            var client = new MongoClient(connectionString);
            var server = client.GetServer();
            var database = server.GetDatabase("test");
            var collection = database.GetCollection<Entity>("entities");

            var cursor = collection.FindAll();

            foreach (Entity book in cursor)
            {
                string name = book.Name;
                string a = Alphabetize(name);
                string value;
                if (dictionary.TryGetValue(a, out value))//http://www.dotnetperls.com/anagram
                {
                    dictionary[a] = value + " " + name;
                }
                else
                {

                    dictionary.Add(a, name);

                }
            }

Ignore the fact the it says “book” and “name” I haven’t changed them yet.

SQL server:

 connection.ConnectionString = ConnectionStrings.connectionString1;
            using (connection)
            using (SqlCommand command = new SqlCommand())
            {
                command.Connection = connection;
                command.CommandText = "SELECT Word FROM Dictionary";
                if (connection.State != ConnectionState.Open) connection.Open();
                using (SqlDataReader sqlReader = command.ExecuteReader())
                {
                    while (sqlReader.Read())
                    {
                        string line = sqlReader.GetString(0);

                        // Alphabetize the line for the key
                        // Then add to the value string
                        string a = Alphabetize(line);
                        string value;
                        if (dictionary.TryGetValue(a, out value))//http://www.dotnetperls.com/anagram
                        {
                            dictionary[a] = value + " " + line;
                        }
                        else
                        {

                            dictionary.Add(a, line);

                        }

                    }

}
}

Each time SQL server performs quicker than MongoDB and the Text file approach performs quicker than both.

I did however notice that insertion for all words was quicker for mongo but that’s not what I’m looking to do.

Is there a quicker way to loop through collections in mongo?

Querying the Text file for a specific word is obviously a lot slower but the performance difference for mongo and SQL weren’t too significant.
0.0450026-ish using mongo. usually quicker
0.0480027-ish using SQl server

Shall I be doing something different with this mongo loop? It’s more than 2 times slower than SQL server…

  • 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-15T11:12:09+00:00Added an answer on June 15, 2026 at 11:12 am

    Both the SQL server and MongoDB need to setup a network connection to your client, execute your query and serialize/unserialize results. This will always be slower than reading from a plain file if you don’t use any indexes or execute more complex queries. Its also a pretty pointless use case for a database. For MongoDB performance is even worse as its a schema less database and it needs to create records in your results dynamically instead of following a fixed table schema.

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

Sidebar

Related Questions

I have a complete stumper, and pose it to all of you to see
I have a ListView styled using the WhistlerBlue.xaml resource dictionary, as downlaoded from Codeplex:
I'm not overly familiar with the SQL Server data dictionary, but I've assumed what
I have a Control Template for Progress Bar in my Resource Dictionary. Complete code
I have a dictionary list of about 58040 words and i don't think jquery
I have a couple of textboxes binded with a Dictionary <TextBox Text={Binding Path=MyField[NotDefinedIndex], Mode=TwoWay}></TextBox>
I have one question about writing a dictionary given a file. I have done
I am in need of some help from you guys. I have a Monotouch
I am trying to make a list box where I have complete control over
I have a complete validation on an obeject and am trying to figure out

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.