-
Notifications
You must be signed in to change notification settings - Fork 50
Open
Description
Im trying Master/Slave replication for something. My goal is to use the slave only for mapreduce tasks, get the results inline and then store it into the master.
My full code is given below.
When i use master for both serverm and servers , then it works, but if u use mapreduce on the slave server in servers, i get following error :-
> [debug] mongo://slaveserver:27017: Connected
[debug] mongo://slaveserver:27017: Initialized as unknown
[debug] Finished scanning... primary? no
{ stack: [Getter/Setter], arguments: undefined, type: undefined, message: 'Could not connect to primary: ' }
[debug] mongo://slaveserver:27017: Disconnected
AFAIK mongo will allow you to run mapreduce on slave as long as the output is inline and setSlaveOk() is set. How do i set that using mongolian?
in the code below, dbs does not have a method getMongo()
var mongofunctions = require('./mongofunctions'),
conf = require('./config/conf'),
helpers = require('./helpers'),
Mongolian = require("mongolian"),
serverm = new Mongolian("masterserver:27017"),
servers = new Mongolian("slaveserver:27017"),
dbm = serverm.db(conf.dbname),
dbs = servers.db(conf.dbname),
beacons = dbs.collection("beacons"),
hourlystats = dbm.collection("hourlystats"),
params = {};
var start = new Date((new Date()).getTime() - 1 * 60 * 60 * 1000 ); // 1 hour ago
start.setUTCSeconds(0);
start.setUTCMilliseconds(0);
start.setUTCMinutes(0);
var end = new Date(start.getTime() + 1 * 60 * 60 * 1000); // start plus an hour
params.timestamp = {
"$gte": start,
"$lt": end
};
beacons.mapReduce(
mongofunctions.cronstatgenerator.map,
mongofunctions.cronstatgenerator.reduce,
{
out: {inline:1},
finalize: mongofunctions.cronstatgenerator.finalize,
query: params
}, function (error, result) {
console.log(error);
result.results.forEach(function(item){
//console.log(item);
hourlystats.save(item);
});
process.exit();
}
)
Metadata
Metadata
Assignees
Labels
No labels