[英]How to query documents in mongodb using mongoose
當我嘗試查找類似const p1 = Profile.find()console.log(p1)的文檔時,我應該獲取該集合中的所有文檔,但是卻得到了不同的廢話。 這是我在mongodb nodejs中的簡單架構
const ProfileSchema = mongoose.Schema({
name: String,
age: Number,
subjects: [String],
late: Boolean
});
const Profile = mongoose.model('profile',ProfileSchema);
const profile1 = Profile.find()
console.log(profile1)
用這個 -
Profile.find({}, function(err, profiles) {
console.log(profiles);
});
請參閱此以獲取更多詳細信息-https://mongoosejs.com/docs/api.html#model_Model.find
const profile1 = await Profile.find({});
由於Mongoose支持async / await,因此我將使包裝函數async
並使用await語法調用find函數。
當您要返回集合中的所有文檔時,還要指出將空對象{}
傳遞給find函數。
此處的更多信息: https : //mongoosejs.com/docs/api.html#query_Query-find
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.