比较Node.js和MongoDB中两个数据库中的数据

时间:2017-06-28 17:20:45

标签: javascript node.js mongodb

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

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

数据包含:

  • 名;
  • id(所有人都是唯一的);
  • CPI。

这是我的代码:



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




1 个答案:

答案 0 :(得分:0)

您是否曾尝试在md5中进行转换并进行比较?

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