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 }*/
}
我還沒有轉換他們在md5。它可能不依賴於數據,但要求數據在兩個數據庫中都應該是相同的。 – YAP