Why is MiniMongo syntax different from MongoDB?


#1

Minimongo:

Posts.find({},{limit:2,sort:{timeCreated:-1}})

MongoDB:

Posts.find().limit(2).sort({timeCreated:-1})

#2

I am not an MDG dev so I can’t tell you about their api design choices. But the reason that Meteor collections are different from the native api is because in the Meteor uses fibers and so must reimplement the Cursor object in a synchronous manner.

Below is a comment from the Meteor source code.

// CURSORS

// There are several classes which relate to cursors:
//
// CursorDescription represents the arguments used to construct a cursor:
// collectionName, selector, and (find) options.  Because it is used as a key
// for cursor de-dup, everything in it should either be JSON-stringifiable or
// not affect observeChanges output (eg, options.transform functions are not
// stringifiable but do not affect observeChanges).
//
// SynchronousCursor is a wrapper around a MongoDB cursor
// which includes fully-synchronous versions of forEach, etc.
//
// Cursor is the cursor object returned from find(), which implements the
// documented Mongo.Collection cursor API.  It wraps a CursorDescription and a
// SynchronousCursor (lazily: it doesn't contact Mongo until you call a method
// like fetch or forEach on it).