Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

210
Views
How to send an object that I read from MongoDB to node js to another js file?

How to send an object that I read from MongoDB to node js to another js file?

I want to send arr to another js file.

 MongoClient.connect(connectionURL, { useNewUrlParser: true }, (error,
 client) => {
     if (error) {
         return console.log("Can't connect to db");
}
const db = client.db(databaseName); jasonArray0 = [
    {
        opentime: 2000,
        image: "cat.jpg"
    }
];
db.collection('stam').insertMany(jasonArray0, (error, result) => {
    if (error) {
        return console.log('Could not insert')
    }
    console.log(result.ops)
})
db.collection('stam').findOne({
    _id: new mongodb.ObjectID("61ca52a727dc9d8f089d04d6")
}, (error, task) => {
    arr.push(task.image)
}) })
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you want the data on the client side, you can create an api route and send the data as json.

If you just want the data in another js file, then you can just require the db model in the file and use db find to use the result there.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!