i am trying to run a search , it is working fine with findOne and recieving data but when i use find it just return some headers and prototypes like this
code
let data = await client
.db("Movies")
.collection("movies")
.find();
console.log(data);
please tell me where i am going wrong
CodePudding user response:
Based on documentation
The toArray() method returns an array that contains all the documents from a cursor. The method iterates completely the cursor, loading all the documents into RAM and exhausting the cursor.
so just try
let data = await client
.db("Movies")
.collection("movies")
.find({}).toArray();
console.log(data);
The type of result in findOne
is Object and the type of result find
is an array