1

我创建了一个名为 Graph 的集合,这是服务器代码:

Graphs = new Meteor.Collection("graphs");
Meteor.publish("graphs", function(){
    return Graphs.find();
} );

在客户端上,我尝试通过以下方式将内容存储在此图表中:

Graphs = new Meteor.Collection("graphs");
Graphs.insert(graph);

我看到它是通过使用流星 mongo 插入到服务器端数据库中的:

db.graphs.count()

返回“1”

在客户端我也有这个代码来监听变化:

Graphs.find().observe({
    added: function(graph) {
        console.log("added graph");
    }, 
    removed: function(graph) {  //removed gets called!
        console.log("removed graph");
    },
    changed: function(graph) {
        console.log("changed graph");
    }
});

但这里变得有趣了,输出是“添加的图”,紧随其后的是“删除的图”。

为什么我将 Graph 插入并与服务器通信,但在客户端,它被添加然后删除?

随后对 Graphs.findOne() 的调用返回“未定义”,就像它仍然是空的一样!?!关于在哪里寻找更多线索的任何想法?

编辑:

如果我在上面的“删除”中放置一个断点,我会得到以下堆栈跟踪:

Graphs.find.observe.removed (graphwiki.js?a150874e1ce3cd4a32d7db02a03cff5239d1ae6e:548) cursor.observeChanges.removed (minimongo.js?daa88dc39d67b40b11d6d6809d72361f9ef6a760:909) (anonymous function) (minimongo.js?daa88dc39d67b40b11d6d6809d72361f9ef6a760:275) _.extend.runTask (fiber_stubs_client .js?52687e0196bc1d3184ae5ea434a8859275702d94:30) _.extend.flush (fiber_stubs_client.js?52687e0196bc1d3184ae5ea434a8859275702d94:58) _.extend.drain (fiber_stubs_client.js?52687e0196bc1d3184ae5ea434a8859275702d94:66) LocalCollection.remove (minimongo.js?daa88dc39d67b40b11d6d6809d72361f9ef6a760:500) self._connection .registerStore.update (collection.js?682caa185350aa26968d4ffc274579a33922f0e6:109) store.(匿名函数) (livedata_connection.js?5d09753571656c685bb10c7970eebfbf23d35ef8:404) _.each.self._updates(匿名函数)(livedata_connection.js?5d09753571656c685bb10c7970eebfbf23d35ef8:984) 。每个。.forEach (underscore.js?ed2d2b960c0e746b3e4f9282d5de66ef7b1a2b4d:78) (匿名函数) (livedata_connection.js?5d09753571656c685bb10c7970eebfbf23d35ef8:983) .each。.forEach (underscore.js?ed2d2b960c0e746b3e4f9282d5de66ef7b1a2b4d:86) _.extend._livedata_data (livedata_connection.js?5d09753571656c685bb10c7970eebfbf23d35ef8:980) onMessage (livedata_connection.js?5d09753571656c685bb10c7970eebfbf23d35ef8:208) (anonymous function) (stream_client_sockjs.js?6ef3fd3e8e39c1c357993f6936512726288ad127:179) .each ..forEach (underscore.js?ed2d2b960c0e746b3e4f9282d5de66ef7b1a2b4d:78) self.socket.onmessage (stream_client_sockjs.js?6ef3fd3e8e39c1c357993f6936512726288ad127:178) REventTarget.dispatchEvent (sockjs-0.3.4.js?6f1db89d6b451d0faf6b7103782d92527931e66a:86) SockJS._dispatchMessage (sockjs-0.3.4 .js?6f1db89d6b451d0faf6b7103782d92527931e66a:1039) SockJS._didMessage (sockjs-0.3.4.js?6f1db89d6b451d0faf6b7103782d92527931e66a:1097) that.ws.onmessage (sockjs-0.3.4.js?6f1db89d6b451d0faf6b7103782d92527931e66a:1238)

这是否暗示了可能出现的问题?

我可以同时插入其他没有角色支持的集合!/汉斯

4

1 回答 1

2

在客户端,您订阅“图表”吗?我认为客户端会将其从其本地集合中删除,因为根据任何订阅,该文档不应该在集合中。

对 Graphs.find() 的后续调用返回“未定义”,就像它仍然是空的一样!?!

我确实觉得这很奇怪。Collection.find() 不总是返回游标吗?

于 2013-07-28T13:26:51.940 回答