0
mongoose를 사용하여 mongoDB를 연결하고 쿼리합니다.mongoDB에서 예상치 못한 결과가 발생했습니다.
지금 나는 다음과 같은 코드가있는 경우 :
return new Promise((resolve) => {
mongoose.connection.db.collection('offer').aggregate([{
$match: {
$or: [
{
ccChecked: {
$lt: new Date(currentDay + 'T00:00:00.000Z')
}
},
{
ccChecked: {
$exists: 0
}
}
],
_id: { $in: offerObjIds }
}
},
{ $sample: { size: 2 } }
], (err, res) => {
console.log('res is', res);
resolve(res);
});
});
제공하는 결과가 괜찮를 우리는 기대 출력을 얻을. 우리는 다음과 같은 쿼리를 가지고 있고, 나는 2로 SAMPLE_SIZE를 제공하는 경우 는하지만 :
const sampleSize = process.env.SAMPLE_SIZE
return new Promise((resolve) => {
mongoose.connection.db.collection('offer').aggregate([{
$match: {
$or: [
{
ccChecked: {
$lt: new Date(currentDay + 'T00:00:00.000Z')
}
},
{
ccChecked: {
$exists: 0
}
}
],
_id: { $in: offerObjIds }
}
},
{ $sample: { size: sampleSize } }
], (err, res) => {
console.log('res is', res);
resolve(res);
});
});
을이 경우에, 나는 정의되지 않은 같은 결과를 얻을. 누군가가 그러한 행동을 설명하는 이유와 process.env 변수를 통해이를 해결하는 방법을 제공 할 수 있습니까?
npm 스크립트에서 "start-offer-service-dev"로 전달하면 : "SAMPLE_SIZE = 2 node_modules/.bin/babel-node src/services /offerService/index.js "라고 입력하면 문자열이나 숫자가 표시됩니까? –
그래, 내 실수, npm 스크립트를 통해 전달 된 인수는 문자열 유형이므로 int로 변환되어야합니다 –
내 업데이트보기 :) 다행스럽게 생각해 냈습니다. 건배. – matt