我正在使用 Real Scheduled Triggers 來運行一些資料驗證的后臺作業。在 Trigger 函式中,我想查詢集合中的所有檔案,但這不起作用。但是當我嘗試 findOne 檔案時,我得到了回應。
//無效,回傳空白
const collection = context.services.get("Cluster0").db("testdocument").collection("testcollection");
return collection.find({}).then((result)=>{ console.log('data : ',JSON.stringify(result)); })
//有效,回傳結果
const collection = context.services.get("Cluster0").db("testdocument").collection("testcollection");
return collection.find({isActive:'true'}).then((result)=>{ console.log('data :',JSON.stringify(result)); })
如果我在這里做錯了什么,任何人都可以提出建議。
uj5u.com熱心網友回復:
我認為您的問題對 //does not work 和 //works 使用了相同的代碼。但我認為有用的是 findOne,這是因為它回傳一個檔案,而 find 回傳一個游標。如檔案中所示,您必須在 .then() 之前使用 .toArray() ,但無論如何都不明顯。
https://docs.mongodb.com/realm/mongodb/actions/collection.find/
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/365114.html
標籤:MongoDB 猫鼬 mongodb-查询
下一篇:如何加入多個mongoDB集合
