We are currently studying Capped Collections and Tailable Cursors in MongoDB to create a notification queue system. However, after creating the simple LinqPad test (code below) that we noticed at startup, Mongo constantly allocates memory until there are resources available, even if we do not insert any records. This allocation continues until all system RAM is used up, after which Mongo simply stops responding.
Since we're new to Capped Collections and Tailable Cursors, I wanted us not to miss something obvious before posting the error.
Note. We tried to use the logging code below with the same results.
- Platform : Windows Server 2012 64bit
- MongoDB : version 2.4.8 64bit
- Driver : official C # 10gen v1.8.3.9
Linqpad script
var conn = new MongoClient("mongodb://the.server.url").GetServer().GetDatabase("TestDB"); if(!conn.CollectionExists("Queue")) { conn.CreateCollection("Queue", CollectionOptions .SetCapped(true) .SetMaxSize(100000) .SetMaxDocuments(100) ); //Insert an empty document as without this 'cursor.IsDead' is always true var coll = conn.GetCollection("Queue"); coll.Insert( new BsonDocument(new Dictionary<string, object> { { "PROCESSED", true }, }), WriteConcern.Unacknowledged ); } var coll = conn.GetCollection("Queue"); var query = coll.Find(Query.EQ("PROCESSED", false)) .SetFlags(QueryFlags.AwaitData | QueryFlags.NoCursorTimeout | QueryFlags.TailableCursor); var cursor = new MongoCursorEnumerator<BsonDocument>(query); while(true) { if(cursor.MoveNext()) { string.Format( "{0:yyyy-MM-dd HH:mm:ss} - {1}", cursor.Current["Date"].ToUniversalTime(), cursor.Current["X"].AsString ).Dump(); coll.Update( Query.EQ("_id", cursor.Current["_id"]), Update.Set("PROCESSED", true), WriteConcern.Unacknowledged ); } else if(cursor.IsDead) { "DONE".Dump(); break; } }
c # windows mongodb capped-collections
Needleski
source share