How to disable clear of Minimongo for specific collection on reconnect?

I have a Minimongo collection which I insert documents into manually on the client side. Like below:

MyCollection._collection.insert(entry);

I have a problem when the app goes offline and the client reconnects again. Then my local collection is cleared. I guess Meteor has some way to check which data I have subscribed to and when syncing again Meteor think the document should be removed. But, for this specific case I want to disable that feature.

Any idea how to solve that?

To reproduce.

Create a new collection:

MyCollection = new Mongo.Collection("myCollection");

Then in the browser console, insert a document manually and then force a disconnect/reconnect:

> MyCollection._collection.insert({_id: "4WDww2iBgxmjpeSkE", someField: "test"})
> Meteor.disconnect();
> Meteor.reconnect();

Can you please add the code of how you created the Collection?

I have updated the description above on how to create the collection and then also insert a document.

Please try to create a “really local” Collection? If you create a collection on the client with a name, then Meteor expects it to represent a collection on the server (in the old days there were even allow&deny to handle direct inserts from the client without methods…).

See also the docs on the name parameter: https://docs.meteor.com/api/collections.html#Mongo-Collection

name String
The name of the collection. If null, creates an unmanaged (unsynchronized) local collection.

So you should create it like so:

const MyCollection = new Mongo.Collection(null);
1 Like

Thanks! That solves the problem!