0

I'd like to clone a minimongo collection so I can do some calculations, get a result, then push those results back to the server.

Assuming this is a suitable pattern, how best can I clone a minimongo collection?

It appears that in the object no longer has a ._deepcopy (1.0.4), and attempting an EJSON.clone exceeds the callstack size for even tiny collections. Underscore's _.clone() only copies by reference.

Alternatively, I could just edit the local collection via collection._collection.update. But if that's the case, what would happen if on the off chance the server updated or removed a doc while it was processing? I watched this video, but am still unclear on that scenario: https://www.eventedmind.com/feed/meteor-how-does-the-client-synchronize-writes-with-the-server

Matt K
  • 4,813
  • 4
  • 22
  • 35

1 Answers1

0

The why behind your pattern escapes me but one solution could be to define a null collection, (docs) copy the records you need to that, do your work, and then copy back the results into the original collection for automatic sync back to the server.

 myLocalCollection = new Mongo.Collection(null);
Michel Floyd
  • 18,793
  • 4
  • 24
  • 39