2

Consider a collection created for server and client:

export const MyCollection = new Mongo.Collection('myCollection')

I receive Documents from the Server due to performance reasons via Methods:

server

Meteor.methods({
  getDocs() {
    return MyCollection.find({ ... }).fetch()
  }
})

On the client I store them inside the local-collection:

client

const LocalCollection = MyCollection._collection
Meteor.call('getDocs', { ... }, (err, docs) => {
  docs.forEach(doc => LocalCollection.insert(doc))
})

Now this works fine but when I run a subscription at another point that also returns documents, that were among those, returned by the method, I receive the following error:

Uncaught Error: Expected not to find a document already present for an add

My question is, whether to flush the Localcollection before the subscription manually or if there is a way to just tell it to "override the existing docs, no matter what"?

Note, that I am using the LocalCollection on the client because allow/deny is by default set to deny on everything and any documents that are inserted like so

Meteor.call('getDocs', { ... }, (err, docs) => {
  docs.forEach(doc => MyCollection.insert(doc))
})

would be rejected to be inserted.

Jankapunkt
  • 8,128
  • 4
  • 30
  • 59

0 Answers0