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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:36:01+00:00 2026-05-26T08:36:01+00:00

I have a collection with 8k+ strings and I need to check if a

  • 0

I have a collection with 8k+ strings and I need to check if a particular string is contained in another string. For example:

StringInDb = "this is a string"
TheOtherString = "this is a long string that contains this is a string"

with linq I used something like:

from s in DB.Table 
where TheOtherString.IndexOf(s.StringInDb ) > -1
select s.StringInDb;

How can I do this (efficiently) in mongodb (even better using the c# .net driver)?

  • 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-26T08:36:02+00:00Added an answer on May 26, 2026 at 8:36 am

    To me this sounds like you need to use map/reduce: map out all your strings from the DB and reduce to the ones contained in your long string. Cant remember the C# off the top of my head. Can find it later if you want.

    Update: The native language of MongoDB is JavaScript and Map/Reduce is run “inside the mongodb engine”, which implies that the map and reduce function must be JavaScript, not C#. They can be called from C# though, as illustrated by this example taken from the official MogoDB C# driver documentation (http://www.mongodb.org/display/DOCS/CSharp+Driver+Tutorial#CSharpDriverTutorial-MapReducemethod). The example counts how many times each key is found in a collection:

    var map =
      "function() {" +
      "    for (var key in this) {" +
      "        emit(key, { count : 1 });" +
      "    }" +
      "}";
    
    var reduce =
      "function(key, emits) {" +
      "    total = 0;" +
      "    for (var i in emits) {" +
      "        total += emits[i].count;" +
      "    }" +
      "    return { count : total };" +
      "}";
    
    var mr = collection.MapReduce(map, reduce);
    foreach (var document in mr.GetResults()) {
      Console.WriteLine(document.ToJson());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a C# collection of strings. Each string is a sentence that can
I have written this code to check for a particular string from a file.
I have a C# list collection that I'm trying to sort. The strings that
I have a collection like this List<int> {1,15,17,8,3}; how to get a flat string
I have an Entity result of List<string> GetTagsData that I need to somehow bind
I have a connection string being passed to a function, and I need to
I have an XML configuration file with a collection of strings like so: <SomeSetting>value</SomeSetting>
I have a collection of string. I want to create an image out of
Suppose you have a collection of Foo classes: class Foo { public string Bar;
I have a Person class which has a String collection of aliases representing additional

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.