my current problem is with the db.collection.find() mongoose command. I\'m relatively new to mongoose/mongodb, but I\'ve gotten the hang of the concepts of it. Here is the t
The object you receive is a Cursor which is an object used to retrieve the actual results.
When you are sure your query will never return more than one object (like in this case where you query by the always unique _id
field), you can use db.collection('Tweet').findOne(
which will return just that object without the additional layer of indirection.
But when your query can potentially return more than one document, you need to use a cursor. To resolve the cursor, you can turn it into an array of documents by using cursor.toArray
:
db.collection('Tweet').find({}, function (err, cursor){
cursor.toArray().forEach(function(doc) {
console.log(doc);
});
})
This is the most simple version. For more information about cursors, refer to the documentation linked above.
By the way: So far you only used the functionality of the native driver. When you want to use Mongoose to query objects, you might want to use the methods of the Mongoose model object.