私は外部データベースに接続し、そのコレクションにアクセスする必要があります。私はそれを使用するとうまく動作しますが、問題はコレクションフックが必要なときです。 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にどのように追加するかを知らない。誰でも助けることができますか?
フックを追加するコードはどこですか? –
その全体の命令: 'TestCollection.after.update(function(userId、doc)...')フックを追加する必要があります。 – blazej24
申し訳ありません、最後の行のコメントは最初に間違っていました。リモートコレクションの内容を変更すると起動します。(外部アプリケーションでは、どのデータベースに接続していますか) '[matb33:collection-hooks](https://atmospherejs.com/matb33/collection-hooks)は流星アプリからの更新をフックします。 OTOHのオブザーバーは* before *フックを実装できません –