Created
May 2, 2013 17:37
-
-
Save craiggwilson/5503913 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using MongoDB.Bson; | |
using MongoDB.Driver; | |
using MongoDB.Driver.Builders; | |
namespace TestSlowGetMore | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var server = new MongoClient("mongodb://localhost:30000,localhost:30001").GetServer(); | |
var db = server.GetDatabase("omni"); | |
var c = db.GetCollection<BsonDocument>("MyCollection"); | |
c.Drop(); // get rid of the data... | |
InsertData(c); | |
var query = Query.And( | |
Query.Matches("category", "foo"), | |
Query.Matches("refid", "bar"), | |
Query.Exists("Topic_ID") | |
); | |
int count = 0; | |
var cursor = c.Find(query); | |
cursor.SetLimit(1000); | |
foreach (var doc in cursor) | |
{ | |
Console.WriteLine("i=" + (++count)); | |
} | |
Console.WriteLine("Finished"); | |
Console.ReadKey(); | |
} | |
private static void InsertData(MongoCollection<BsonDocument> collection) | |
{ | |
var random = new Random(); | |
var categories = new [] { "foo", "other" }; | |
var refids = new [] { "bar", "other" }; | |
for (int i = 0; i < 10000; i++) | |
{ | |
var doc = new BsonDocument | |
{ | |
{ "category", categories[random.Next(0, categories.Length)] }, | |
{ "refid", refids[random.Next(0, refids.Length)] }, | |
{ "Topic_ID", true, random.Next(0,100) < 50 } // only include sometimes | |
}; | |
collection.Insert(doc); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment