forked from mongodb/node-mongodb-native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreplicaTest.js
49 lines (40 loc) · 1.19 KB
/
replicaTest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var mongo = require('../lib/mongodb' );
var http = require( 'http' );
var N = 1000000;
var replyNo = 1;
var dbName = 'something';
var collName = 'else';
var collection = null;
var replSet = new mongo.ReplSetServers( [ new mongo.Server( 'localhost', 27017, { auto_reconnect: true } ) ] );
var db = new mongo.Db( dbName, replSet );
var runHttp = function () {
http.createServer(function (req, res) {
collection.findOne( {"name":"somename"}, function( err, item ) {
var answer = '';
if ( !item || err) {
answer = 'Not found.';
} else {
answer = 'Found.';
}
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end( answer );
});
/*res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Found.');*/
}).listen(1080, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1080/');
}
db.open( function ( err, p_db ) {
db.collection( collName, function( err, coll ) {
collection = coll;
// runHttp();
collection.findOne( {"name":"somename"}, function( err, item ) {
if ( !item || err) {
console.log('Not found.');
} else {
console.log('Found.');
}
db.close();
});
});
});