title: Searching for string pattern that matches string in array in MongoDB C#
body: <p>I can't seem to get this working in MongoDB using the C# driver. I have spent a while on it now without any luck. I have an array of strings and I want to return all mongo docs that contains any of the words in the array.</p>
  
  <p>I get the array string from a collection. And the array would contain items as such: ["moon", "cow", "Neil"]</p>
  
  <p>I have a collections as such:</p>
  
  <pre><code>{_id: "xxxxx1", story:"The cow jump over the moon"}
  {_id: "xxxxx2", story:"Neil Armstrong landed on the moon in the 1960s"}
  {_id: "xxxxx3", story:"The moon is very bright tonight."}
  {_id: "xxxxx4", story:"Itsy winchie spider climb up the spout. moon is cool."}
  {_id: "xxxxx5", story:"moon"}
  {_id: "xxxxx6", story:"no text match here mate"}
  </code></pre>
  
  <p>So from the array and collection, the first 5 documents should be released since they contain either "moon", "cow" or "Neil". The last document shouldn't be returned since it doesn't contain any of those words.</p>
  
  <p>Below is my code that I am stuck on. It only returns document xxxx5 since it contains moon and nothing else. I am almost there, but not quite. Hope someone can help.</p>
  
  <pre><code>var userId = "12345";
  var connectionString = ConfigurationManager.AppSettings["MongoDBConnectionString"];
  var server = MongoServer.Create(connectionString);
  var database = server.GetDatabase(ConfigurationManager.AppSettings["MongoDBDatabase"]);
  
  var fCollection = database.GetCollection&lt;BsonDocument&gt;("words");
  var fQuery = Query.EQ("UserId", userId);
  var fDoc = fCollection.FindAs&lt;Words&gt;(fQuery).SetFields(Fields.Exclude("_id"));
  var list = fDoc.ToList();
  
  var words = list.Select(t =&gt; t.Word).ToArray();
  
  var collection = database.GetCollection&lt;BsonDocument&gt;("stories");
  var query = Query.In("story", new BsonArray(words);
  
  
  var doc =     collection.Find(query).SetSortOrder(SortBy.Descending("Submitted")).Skip(skip).Take(limit);
  
  var jsonWriterSettings = new JsonWriterSettings { OutputMode = JsonOutputMode.Strict };
  return doc.ToJson(jsonWriterSettings);
  </code></pre>