![](/img/trans.png)
[英]How do I add new object or push into array Mongodb Compass NodeJS Express (update is not a function)?
[英]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.