A JS Harmony MongoDB/NeDB ODM
MongoSmash is a super-minimal MongoDB/NeDB ODM for Node.js. It lets you
NeDB. MongoSmash is implemented using
Object.observe, and so is subject to its
limitations on changes it can track, and requires Node 0.11.10+. You'll need to
invoke node with the
WARNING: MongoSmash is incomplete. It works, but it's missing a lot of features!
var dbURI = 'mongodb://127.0.0.1:27017/test';MongoClient;
You can run the benchmarks yourself as shown below. The results here are from
K-ops/sec means "thousand calls of the given function per
second", so higher is better.
$ node -vv0.11.11$ npm run bench> firstname.lastname@example.org bench /Users/benglish/mongosmash> node --harmony bench/testFailed to load c++ bson extension, using pure JS version........................OPERATION | MONGOOSE KOps/s | MONGOSMASH KOps/s | DIFF %------------------------------------------------------------new | 34.026 | 98.806 | 190.38save | 3.504 | 4.999 | 42.67find | 2.627 | 2.91 | 10.77edit | 55.441 | 174.096 | 214.02saved edited | 2.425 | 3.946 | 62.72delete | 5.915 | 6.99 | 18.17
Of course a head-to-head comparison with Mongoose isn't necessarily realistic, since MongoSmash doesn't do things like validations. I recommend using a tool like revalidator to do your object validations.
You must pass in either an already-connected MongoDB connection (from
nove-mongodb-native) or the NeDB module in its entirety. For the moment, only
in-memory NeDB is supported.
Sets up an object (
obj) to have its changes tracked so we can
modelName is equivalent to a MongoDB collection name. If you're
doing this, you probably actually want
Does a MongoDB
update depending on the current status of the
object. The error-first-style
callback, which will call with a resultant
object if it's a new object. The new object will also have a brand-new
new and then
callback error-first-style with an array of objects matching the
query. For the moment, projections are not supported.
obj from the database, callback only takes in error.
Please do! Pull requests, bug reports and feature requests are more than welcome, and should be done using Github PRs and Issues. Please try to conform to existing style (though I'm not very stylish), and don't forget tests and docs! Also, if making a performance improvement, feel free to update the benchmark data. TODOs are in Github Issues.