나는 Ionic 2
및 Meteor
과 MongoDB
을 사용하는 채팅 앱이 있습니다. 그것은 완벽하게 작동합니다.minimongo에 배열 객체 추가
그러나 모든 것이 서버의 MongoDB
에 저장되므로 사용자가 메시지를보고 싶을 때마다 클라우드에서 실행중인 Meteor/Mongo
서버에 연결해야합니다. 또한 한 사용자가 chat
을 삭제하면 MongoDB
에서 chat
이 삭제되고 해당 다른 사용자도 chat
이 삭제됩니다.
나는 messages
이 장치에 로컬로 개최됩니다 WhatsApp에 (나는 SQLite
을 사용하고 있습니다)로 비슷한 기능을 원하는, 모두 사용자가이를 다운로드 할 때까지 만 messages
새가 클라우드에서 개최됩니다.
현재 내 응용 프로그램은 Mongo.Cursor<Chat>
개체를 반복합니다. 또한이 개체 (this.chats.observe({changed: (newChat, oldChat) => this.disposeChat(oldChat), removed: (chat) => this.disposeChat(chat)});
)를 관찰합니다.
로컬로 저장 한 SQLlite
의 데이터 (Array<Chat>
)는 chat
입니다. 그것은 Mongo.Cursor<Chat>
에 SQLite
데이터 (Array<Chat>
)를 추가 할 수
질문
인가? 그렇게 할 때 서버에 이 아니라 minimongo
에 추가하려고합니다.
감사
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, 의견에 감사드립니다. 나는 '몽고. 콜렉션'을 사용하지 않고'몽고. Cursor에서'observe '를 사용하고 있습니다. 'Collection'을 사용하여 동일한 작업을 수행 할 수 있습니까? – Richard
문서에 따르면, 나는'Collection'을'관찰 '할 수 없다. 그래서 나는 틀린 것이 아니라면 위의 내용이 적절한 대답이라고 생각하지 않습니까? – Richard
솔루션이 작동합니다. 감사합니다. – Richard