一、安装依赖

  1. yarn add mongodb

二、app.js

  1. const { MongoClient} = require('mongodb');
  2. // Connection URL
  3. const url = 'mongodb://121.36.197.5:10010';
  4. const client = new MongoClient(url);
  5. const dbName = 'movie';
  6. async function main() {
  7. await client.connect();
  8. console.log('Connected successfully to server');
  9. const db = client.db(dbName);
  10. const collection = db.collection('user');
  11. const result = await collection.find({}).toArray();
  12. return result;
  13. }
  14. main().then(res=>{
  15. console.log(res)
  16. })
  1. nodemon app.js