2017-06-28 71 views
0

两个数据库比较数据我已经在的Node.js和MongoDB一个服务器创建了两个数据库(1- btech2014 & 2- btechre2014)。在的Node.js和MongoDB

我想的btech2014数据与btechre2014比较。如果它们是相同的,那么我应该能够获得btech2014的输出数据。否则我应该回复一条消息。 如何比较同一服务器上的两个数据库?

的数据包含:

  • 名称;
  • id(对所有人都是唯一的);
  • cpi。

这里是我的代码:

var findData = function(db, callback) { 
 
\t var cursor = db.collection('btech2014').find();//data from our processing task 
 
\t var cursor2 = db.collection('btechre2014').find();//data form replica 
 
\t cursor.each(function(err, doc) { 
 
\t \t /*cursor2.each(function(err, doc2) { 
 
\t \t assert.equal(err, null); 
 
\t \t if (doc != null && doc == doc2) { 
 
\t \t \t console.log(doc); 
 
\t \t \t data[i]=doc; 
 
\t \t \t i++; 
 
\t \t \t count++; 
 
\t \t } else { 
 
\t \t \t callback(); 
 
\t \t } 
 
\t })*/ 
 
\t \t assert.equal(err, null); 
 
\t \t if (doc != null) { 
 
\t \t \t console.log(doc); 
 
\t \t \t data[i]=doc; 
 
\t \t \t i++; 
 
\t \t } else { 
 
\t \t \t callback(); 
 
\t \t } 
 
\t }); 
 
\t /*var cursor = btech2014.find().forEach(function(doc1){ 
 
\t \t var cursor2 = btechre2014.findOne({name: doc1.name}); 
 
\t \t //var flag = JSON.stringify(doc1)==JSON.stringify(doc2); 
 
\t \t if(JSON.stringify(doc1)==JSON.stringify(doc2)){ 
 
\t \t \t console.log(doc1); 
 
\t \t } 
 
\t \t else{ 
 
\t \t \t console.log('system on attack!!'); 
 
\t \t } 
 
\t });*/ 
 
\t /*if(count != 5){ //total 5 entries to be checked 
 
\t \t console.log('there is an attack on the system!'); 
 
\t }*/ 
 
}

回答

0

你有没有试过在两者转换的MD5和比较?

我不知道你有多少行,也许作品...

+0

我还没有转换他们在md5。它可能不依赖于数据,但要求数据在两个数据库中都应该是相同的。 – YAP