Strange cappedCollection behaviour?


#1

Mac OSX
1.3.2.4

In my lib/collections.js I tried to make a capped collection :

var Collections = {};

FutureTasks = Collections.FutureTasks = new Mongo.Collection('future_tasks', {capped: true, size:5242880, max:10});

from https://docs.mongodb.com/manual/core/capped-collections/

which is used in server.js to be updated in a cron job every minute from RESTful service with JSON data to be populated.

After I applied 13 documents it starts to delete, but deletes all the way to just 1 single document.
But on the meteor mongo shell it still says 13.

db.future_tasks.count()
13

But

db.future_tasks.isCapped()
false

Why is that?


#2

Your capped collection config doesn’t look quite right. Instead of setting it up via the Mongo.Collection constructor, try:

FutureTasks = Collections.FutureTasks = new Mongo.Collection('future_tasks');
FutureTasks._createCappedCollection(5242880, 10);

For more details, see:


#3

Hi Huge,

lib/collections.js

// FutureTasks = Collections.FutureTasks = new Mongo.Collection('future_tasks', { capped : true, size : 5242880, max : 50 });

FutureTasks = Collections.FutureTasks = new Mongo.Collection('future_tasks');
FutureTasks._createCappedCollection(5242880, 5);

Uncaught Error: Can only call _createCappedCollection on server collections

EDIT:

Works when placed in server.js

FutureTasks._createCappedCollection(5242880, 5);

meteor:PRIMARY> db.future_tasks.isCapped()
true

But after adding more than 5 documents, say 6, then on UI Griddle table I see 3, then 2, then 1, …well now 0
and meteor mongo shell is still ?

db.future_tasks.count()
5

and CTRL-M on UI with the meteortoys:allthings installed, I see still 5 items, though only the _id but nothing else.

So it seems like it has removed docs but not the mongodB _id, hence I see count of 5 and yet the empty Griddle UI table discrepancy, so in a way it has resulted in items deleted, with only its _id remaining?

Is this also forward compatible with 1.4.1.1?


#4

I tried this method but I get _createCappedCollection is not a function