mysql-shadow
mysql-shadow copied to clipboard
collection insert duplicate
During Collection insertion on either from the client or to the server via Meteor.methods the mongodb collection data duplicated as you can see here
However the data was successfully replicated on the MySQL database as seen here:
Hi Ralph,
I don't have that issue. Are you sure everything is OK with your code?
Can you post some example?
Here's the code that I wrote:
This code below is triggered from a different template
'click .btnGenRandom': function (e, tmpl) {
function alphanumeric_unique(strlength) {
return Math.random().toString(36).split('').filter( function(value, index, self) {
return self.indexOf(value) === index;
}).join('').substr(2,strlength);
}
Meteor.call("insertBarcode", alphanumeric_unique(11).toUpperCase(), 1, function(error, result){
if(error){
console.log("error", error);
}
if(result){
console.log(result);
}
});
Here's the code that I copied from the read.me
Meteor.startup( function() {
var connectionName = "my_connection"; // Name your connection as you wish
CreateMySQLConnection(connectionName, {
host : '10.186.60.19', // MySQL host address or IP
database : 'RalphDB', // MySQL database name
user : 'dbuser', // MySQL username
password : 'dbuser' // MySQL password
});
OpenMySQLConnection(connectionName, function(e) {
if(e) { console.log(e.reason);
return;
}
console.log("Connected. Initializing shadow...");
CreateMySQLShadow(connectionName, {}, function(e) {
if(e) {
console.log(e.reason);
return;
}
console.log("Shadow initialized. Copying data to mongo...");
MySQLShadowSyncAll(connectionName, {}, function(e) {
if(e) {
console.log(e.reason);
return;
}
// If you want changes to your collections to be automatically replicated back to MySQL do something like this:
// MySQLShadowCollection(SomeCollection, connectionName);
MySQLShadowCollection(FoilTank, connectionName,{});
MySQLShadowCollection(IndiboxFoil, connectionName,{});
console.log("Success.");
});
});
});
});
Subscribe & Publish
Meteor.publish("indiboxData", function(){
return IndiboxFoil.find();
});
Meteor.subscribe("indiboxData");
Things I have done so far:
- Use autopublish + mysql-shadow, result have duplicate
- Use subscribe/publish work instead of autopublish still duplicate
- Disable mysql-shadow and all the subscribe/publish work fine.
Every time I insert a data to my collection the first data seems to duplicated or repeated, See picture above on my first report
Is that happening only with the first inserted doc? (and other docs are inserted normally, once) ?
My test have an initial data on the MySQL database then replicated to mongodb, and I inserted a data.
Just now I checked, if there are no data on both databases, my collection insert will duplicate all the first data but the MySQL data showed everything I inserted without duplicate