2017-08-08 6 views
1

私は外部データベースに接続し、そのコレクションにアクセスする必要があります。私はそれを使用するとうまく動作しますが、問題はコレクションフックが必要なときです。 Collection.after.insert(function(userId、doc))。フックは発射されていません。私は次のコードを持っています:Meteorリモートコレクション - フックが機能しない

// TestCollection.js 

let database = new MongoInternals.RemoteCollectionDriver("mongodb://127.0.0.1:3001/meteor", 
{ 
    oplogUrl: 'mongodb://127.0.0.1:3001/local' 
}); 
let TestCollection = new Mongo.Collection("testCollection", { _driver: database }); 
module.exports.TestCollection = TestCollection; 
console.log(TestCollection.findOne({name: 'testItem'})); // writes out the item correctly 

// FileUsingCollection.js 
import { TestCollection } from '../collections/TestCollection.js'; 
console.log(TestCollection.findOne({name: 'testItem'})); // writes out the item correctly second time 

TestCollection.after.update(function (userId, doc) { 
    console.log('after update'); 
}); // this is NOT being fired when I change the content of remote collection (in external app, which database I am connected) 

この作品を作るには?

編集:私はそれについて多くの時間を読んでいると私はそれはのようなものを接続することかもしれないと思う

: - oplog - さらにreplicaSet

しかし、私は流星する初心者ですし、見つけることができませんそれらについて何があるのですか?私はMONGO_OPLOG_URLを設定して、私はここで読んでデータベースドライバにoplogパラメータを追加しました:https://medium.com/@lionkeng/2-ways-to-share-data-between-2-different-meteor-apps-7b27f18b5de9 しかし何も変わりません。そして、私はこのレプリカセットをどのように使うべきか、それをURLにどのように追加するかを知らない。誰でも助けることができますか?

+0

フックを追加するコードはどこですか? –

+0

その全体の命令: 'TestCollection.after.update(function(userId、doc)...')フックを追加する必要があります。 – blazej24

+0

申し訳ありません、最後の行のコメントは最初に間違っていました。リモートコレクションの内容を変更すると起動します。(外部アプリケーションでは、どのデータベースに接続していますか) '[matb33:collection-hooks](https://atmospherejs.com/matb33/collection-hooks)は流星アプリからの更新をフックします。 OTOHのオブザーバーは* before *フックを実装できません –

答えて

0

また、あなたはまた、より多くの機能goto linkについては'addedBefore(id, fields, before)''changed(id, fields)''movedBefore(id, before)''removed(id)'

を持つことができます

var observer = YourCollections.find({}).observeChanges({ 
      added: function (id, fields) { 

      } 
     }); 

、コードの下のような何かを試すことができます。

+0

それは動作しません、それは同じデータベースに関連付けられている別のアプリケーションによって行われたコレクションの変更を観察しません。 – blazej24

+0

Observerが動作しました!Meteorを1.5.1にアップデートしてコードをクリーンアップしましたが、今は正常です。ありがとうございます! – blazej24

関連する問題