« Back to Index

MongoDB: when using the find() method on a Collection you’ll need to toArray() on results as it doesn’t run your query but instead returns new Cursor instance

View original Gist on GitHub

example.js

// Using <https://github.com/Colingo/continuable-mongo> api

var collection = client.collection('someCollection');

collection.insert([{
    some: 'key',
    value: 'pair'
}], function (err, inserted) {
    collection.find({
        some: 'key'
    }).toArray(function (err, results) {
        // results = found documents
    });
});