配列からコレクションに文字列を保存しようとしています。これが以前に存在しなかった場合はコレクションに文字列を保存しますが、文字列を保存した後、これはnullです
ここに私のソースコードがあります:
exports.procc = function(req, res) {
//combinatorial is the array that contains the strings
var k = combinatorial.length, m = 0;
var collection = db.collection('searchtb');
collection.count({'search': b}, function(err, count) {
for (m = 0; m < k; m++) {
//Here prints the value of the varible
console.log(combinatorial[m]);
//Here the same variable is null
collection.count({'search': combinatorial[m]}, function(err, count) {
c=count;
if(c==0){
collection.insert({'search': combinatorial[m],'hits':1});
}
});
}
});
res.end();
};
しかし、「カウント」なしで次のコードを書くと、文字列は正しい方法で保存されます。
for (m = 0; m < k; m++) {
collection.insert({'search': combinatorial[m],'hits':1});
}
何が私のエラーなのかわかりません。ご協力いただきありがとうございます