Reputation: 41
When i try to find a document like const p1 = Profile.find() console.log(p1) i should get all document in that collections but i'm getting different crap. this is my simple schema in 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)
Upvotes: 0
Views: 1441
Reputation: 168
const profile1 = await Profile.find({});
Since Mongoose supports async/await I would make the wrapping function async
and call your find function using the await syntax.
Also make a point to pass in an empty object {}
to your find function when you want to return all the documents in the collection.
More information here: https://mongoosejs.com/docs/api.html#query_Query-find
Upvotes: 0
Reputation: 3589
Use this -
Profile.find({}, function(err, profiles) {
console.log(profiles);
});
Refer this for more details - https://mongoosejs.com/docs/api.html#model_Model.find
Upvotes: 1