簡體   English   中英

我如何 output 所有 collections 在 NodeJS (MongoDB Compass) 中使用 MongoDB

[英]How do I output all collections with MongoDB in NodeJS (MongoDB Compass)

Able to output one object based on the filter below, but in MongoDB there are 500 objects, so how do I output all the objects inside the collection of the MongoDB? 已經嘗試過 find()。 但后來我得到了這樣的東西。

在此處輸入圖像描述

MongoDB 中的對象如下所示:

在此處輸入圖像描述

 const client = new MongoClient(uri, { useNewUrlParser: true, useUnifiedTopology: true, }); async function run() { try { await client.connect(); const database = client.db('database'); const music = database.collection('music'); const single = await music.find(); console.log(single); } finally { await client.close(); } }

你可以這樣嘗試嗎:

const { MongoClient } = require('mongodb');
const client = new MongoClient(uri, { useUnifiedTopology: true }); //Options are optional
const db = await client.connect().db();
const results = await db.collection('music').find().toArray();
console.log(results);

我認為您缺少toArray()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM