私はIonic 2
とMeteor
とMongoDB
を使っているチャットアプリを持っています。それは完全に動作します。配列オブジェクトをminimongoに追加
ただし、すべてがサーバーのMongoDB
に保存されているため、ユーザーは自分のメッセージを表示するたびに、クラウド内で実行されているMeteor/Mongo
サーバーに接続する必要があります。また、1人のユーザーがchat
を削除すると、MongoDB
のchat
が削除され、対応する他のユーザーのchat
も削除されます。
私はmessages
が(私はSQLite
を使用しています)、デバイス上でローカルに保持され、両方のユーザーがそれらをダウンロードするまで、唯一の新しいmessages
は、クラウド内に保持されているのWhatsAppと同様の機能をしたいと思います。
現在のところ私のアプリはMongo.Cursor<Chat>
オブジェクトを反復処理します。また、このオブジェクト(this.chats.observe({changed: (newChat, oldChat) => this.disposeChat(oldChat), removed: (chat) => this.disposeChat(chat)});
)を観察します。
私がローカルに保管しているSQLlite
のデータ(Array<Chat>
)を取得します。
質問
はMongo.Cursor<Chat>
にSQLite
データ(Array<Chat>
)を追加することが可能ですか?私がそうするとき、私はちょうどminimongo
に加えて、サーバー上のMongoDB
ではない。
おかげで、以下のアドバイスあたり
UPDATE
Aspが、私は次のようにします。それが動作するかどうか
let promise: Promise<Mongo.Cursor<Chat>> = new Promise<Mongo.Cursor<Chat>>(resolve => {
this.subscribe('chats', this.senderId, registeredIds,() => {
let chats: Mongo.Cursor<Chat> = Chats.find(
{ memberIds: { $in: registeredIds } },
{
sort: { lastMessageCreatedAt: -1 },
transform: this.transformChat.bind(this),
fields: { memberIds: 1, lastMessageCreatedAt: 1 }
}
);
this.localChatCollection = new Mongo.Collection<Chat>(null);
console.log(this.localChatCollection);
chats.forEach(function (chat: Chat) {
console.log('findChats(): add chat to collection: ' + chat);
this.localChatCollection.insert(chat);
});
が更新されます。
UPDATE
私は、次の操作を行い、それinserts
chat
オブジェクト:私はグローバルlocalChatCollection
を定義した場合
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);
localChatCollection.insert(chat);
});
しかし、それはinsert
chat
オブジェクトません。エラーはありませんが、プロセスはinsert
行で停止します。
private localChatCollection: Mongo.Collection<Chat> = new Mongo.Collection<Chat>(null);
....
this.localChatCollection.insert(chat);
私はこれがグローバルに定義されたcollection
に挿入する方法を得ることができます任意のアイデア?
こんにちはcobberboy、フィードバックありがとうございます。私は 'Mongo.Collection'ではなく' Mongo.Cursor'を使用しています。私は 'Cursor'で' observe'を使っています。 'Collection'と同じことをするのは可能でしょうか? – Richard
文書によると、私は 'コレクション'を '観察することができません。だから私は間違っていない限り、上記は適切な答えだとは思わない? – Richard
解決策はありますか、ありがとうございます。 – Richard