First, you'll need to create an index on that field to ensure good query performance. Execute this command from the MongoDB console:
db.Contacts.ensureIndex({ "Personal.FirstName": 1 }, { "sparse": true })
Then you can query the Collection database in your C# code:
ConnectionStringSettings connectionStringSettings = ConfigurationManager.ConnectionStrings["analytics"];
var url = new MongoUrl(connectionStringSettings.ConnectionString);
var client = new MongoClient(connectionStringSettings.ConnectionString);
MongoServer server = client.GetServer();
MongoDatabase database = server.GetDatabase(url.DatabaseName);
string searchName = "Meghan";
MongoCursor results =
database
.GetCollection("Contacts")
.Find(Query.Matches("Personal.FirstName", "^" + searchName))
.SetFields("Personal.FirstName")
.SetLimit(10);
foreach (BsonDocument r in results)
{
string firstName = r["Personal"]["FirstName"].AsString;
}
Keep in mind that you're getting pretty low-level with this, circumventing the Sitecore API. If the structure of data changes in the future, you'll need to adjust the query.
Also, never change contact objects directly.