gpt4 book ai didi

javascript - 如何在mongodb中拼接两个集合的长度,并在一个变量中得到两个集合的总长度?

转载 作者:可可西里 更新时间:2023-11-01 10:41:03 27 4
gpt4 key购买 nike

下面是我的代码。我需要在单个变量中获取两个集合的总长度。

audiofiles.find(),function(err,res){
console.log(res.length);
var count1 = res.length;
}
videofiles.find(),function(err,res){
console.log(res.length);
var count2 = res.length;
}
var totalcount = parseInt(count1+count2);
console.log(totalcount);

最佳答案

你试过吗:

 var totalcount = parseInt(parseInt(count1)+parseInt(count2));

__

局部到全局范围

var count1;
var count2;
audiofiles.find(),function(err,res){
console.log(res.length);
count1 = res.length;
}
videofiles.find(),function(err,res){
console.log(res.length);
count2 = res.length;
}
var totalcount = parseInt(parseInt(count1)+parseInt(count2));
console.log(totalcount);

注意:这过于冗长,但它应该有效。希望..

关于javascript - 如何在mongodb中拼接两个集合的长度,并在一个变量中得到两个集合的总长度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43337390/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com