Answer the question
In order to leave comments, you need to log in
How to pass the result of a query to another function?
The question is elementary, something caused difficulty.
First I find the parameter
db.collection("collection").findOne({colID: 1}, function(err, result) {
if (err) throw err;
console.log(result.title);
client.close();
});
data = { title: result.title }
db.collection('collectiontwo').insertOne(data, function(err, res) {
if (err) throw err;
console.log('1 document inserted');
client.close();
});
Answer the question
In order to leave comments, you need to log in
const result = await db.collection("collection").findOne({colID: 1});
const res = await db.collection('collectiontwo').insertOne({title: result.title});
client.close();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question