MongoError“服务器实例池被破坏”

时间:2017-10-04 11:46:31

标签: javascript angularjs json mongodb typescript

我试图编写一个角度应用程序来获取来自fullcontact API的信息作为json并将其插入到mongodb.I可以成功获取json但是当我尝试将其插入mongodb时。我解决了其他问题,但卡在了这一个。

 ERROR :
       MongoError {name: "MongoError", message: "server instance pool was destroyed", stack: "MongoError: server instance pool was destroyed↵   …    at http://localhost:4200/main.bundle.js:60:12"}



Kisiler.js 
var mongo = require('mongodb');
var Server = mongo.Server,
Db = mongo.Db,
BSON = mongo.BSONPure;

var server = new Server('localhost', 27017, {auto_reconnect: true});
db = new Db('kisidb', server);

db.open(function(err, db) {
if(!err) {


console.log("Connected to 'kisidb' database");
db.collection('kisiler', {strict:true}, function(err, collection) {
if (err) {
console.log("The 'kisiler' collection doesn't exist. Creating it with 
sample data...");
}
});
}
});

exports.kisiEkle = function(veri) {
var deger = new Object();
var deger = veri;
db.collection('kisiler', function(err, collection) {
 collection.insert(deger, {safe:true}, function(err, result) {
if(err){
console.log(err);
}else {
console.log(result);
}
});

});
}


user.component.ts 

const kisi = require('../../../../routes/kisiler');

// user.component.ts

console.log(data);  // type of data is json.
kisi.kisiEkle(data);

0 个答案:

没有答案