MongoDB execute script returns _mongo and _db information

132 Views Asked by At

I'm executing a MongoDB script via the Kohana MangoDB ORM.

Here's the code to be executed:

var query {
    date: date
};
var indexes = db.organisation_booking_indexes.find(query);

If I do .findOne(query) I get the specific result as an array. However just doing .find(query) returns other stuff like _mongo and _db instead of an array of the expected results.

How do I return just the documents I'm looking for?

1

There are 1 best solutions below

0
Julien On

It appears that some objects can't be returned "as is" using JS. In this case Mongo return the Cursor

Try:

var indexes = db.organisation_booking_indexes.find(query).toArray();

This will convert the result in a "compatible" object. Take a look at this post to get more details: MongoDB: Error executing stored JavaScript function