Add array object to minimongo

Hi All,

I have a chat app, that is using Ionic 2 and Meteor with MongoDB. It works perfectly.

However, everything is stored in the MongoDB on the server, so each time a user wants to view their messages, they need to be connected to the Meteor/Mongo Server running in the cloud. Also, if one user deletes their chat, it will delete the chat on the MongoDB, and the corresponding other user will also have their chat deleted.

I would like similar functionality as WhatsApp where the messages are held locally on the device (I am using SQLite), and only new messages are held in the cloud until both users download them.

Currently my app iterates over a Mongo.Cursor<Chat> object. It also observes this object (this.chats.observe({changed: (newChat, oldChat) => this.disposeChat(oldChat), removed: (chat) => this.disposeChat(chat)});).

I get chat data from SQLlite that I have stored locally (Array<Chat>).


Is it possible to add the SQLite data (Array<Chat>) to the Mongo.Cursor<Chat>? When I do so, I want to just add to minimongo and not MongoDB on the server.



Copy it to a collection and use the collection:

var localChatCollection = new Mongo.Collection(null)


When I do the following, it inserts the chat object:

      let promise: Promise<Mongo.Collection<Chat>> = this.findChats();
      promise.then((data: Mongo.Collection<Chat>) => {

        let localChatCollection: Mongo.Collection<Chat> = new Mongo.Collection<Chat>(null);
        data.find().forEach(function (chat: Chat) {
          console.log('==> ' + chat);

However, if I define the localChatCollection globally, it does not insert the chat object. There are no errors but the process just stops on the insert line.

private localChatCollection: Mongo.Collection<Chat> = new Mongo.Collection<Chat>(null);

Any ideas how I can get this to insert into a globally defined collection?

This works, but I don’t think it is the most elegant solution:

        let that = this;
        data.find().forEach(function (chat: Chat) {