
Security News
MCP Community Begins Work on Official MCP Metaregistry
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Wongo is an ODM-like library intended to simplify working with mongodb. The intent is to have feature parity with mongoosejs, but simplier and cleaner. Part of that simplicity is only supporting three crud methods; save, remove, and find which should cover 99% of use cases. Of course, if you want to get down and dirty, the native mongodb driver is exposed.
npm install wongo
wongo = require 'wongo'
wongo.connect(url)
wongo.schema = 'Mock',
fields:
name: String
createdOn: Date
doc = {name: 'Woof'}
wongo.save 'Mock', doc, (err, result) -> # result is the saved raw json object
wongo.save 'Mock', documents, (err, result) -> # result is the saved json object array
partialDoc = {_id: '5', name: 'Wallace'}
where = {name: 'Gromit'}
wongo.save 'Mock', partialDoc, where, (err, result) ->
documents = [{name: 'bil'},{name: 'sig'},{name: 'boo'}]
where = {accountId: '65'}
wongo.save 'Mock', documents, where, (err, result) ->
query = {name: 'mint'}
wongo.find 'Mock', query, (err, docs) -> # docs is a raw json array of objects
document = {_id: 'uniqueId'}
wongo.remove 'Mock', document, (err) -> # doc has been removed
documentId = 'uniqueId'
wongo.remove 'Mock', documentId, (err) -> # doc has been removed
Just like mongoosejs, everything starts with a Schema. Schemas map to collections in mongodb. Supported Property Types:
Setting a {type: 'mixed'} on a schema field wongo will just assume you are going to handle the type. This means, pruning will leave the field, it will not look for validation, or otherstuff. 'mixed' is just an example, you could name it anything and then write a plugin which will do something with it. Or extend the validator to validate against it.
wongo.schema = 'Mock',
fields: # fields acts just like the normal mongoose schema
name: {type: String}
embeddedDocArray: [ # embedded docs and everything are just like mongoose
name: String
validia: {type: Number, min: 3, max: 9, required: true}
]
createdOn: {type: Date, required: true}
hooks: # participate in middleware
beforeSave: (document, schema, next) -> # document is a json doc
afterSave: (document, schema, next) -> # note, this allows async unlike mongoose
validate: (document, schema, next) -> # we can even override wongo's validation with our own
prune: false # or set the pruner to false if we dont want wongo to trim our documents
beforeFind: (query, schema, next) -> # modify a find query before it is run
afterFind: (query, schema, documents, next) -># after we find a group of documents, we can do something with them
beforeRemove: (document, schema, next) ->
afterRemove: (document, schema, next) ->
indexes: [ # add standard mongodb compliant indices
{name: 1}
[{name: 1}, {unique: true}] # use an array to pass in index options
]
Validation should hold feature parity with mongoose.js
There are four support find methods:
query = {select: '_id name', where: {name: 'Moo'}, limit: 5}
The query object has the following top-level properties.
If 'where' isn't found, wongo wraps the query object in a where statement.
query = {name: 'Boo'}
is equivalent to
query = {where: {name: 'Boo'}}
Middleware is defined on the schema (under the hooks property) or in the wongo.options. Middleware is pushed into an array when the schema is registered. So, post schema registration, if you want to add more middleware, you need to add it directly to the array. Examples of this are shown in the plugins module.
wongo.schema = 'Mock',
hooks:
beforeSave: (document, schema, next) ->
afterSave: (document, schema, next) -> # add your own handler for what happens after a save
validate: true # will use default wongo validator
prune: false # turns off the wongo pruner
beforeFind: (query, schema, next) ->
afterFind: (query, schema, documents, next) ->
beforeRemove: (document, schema, next) ->
afterRemove: (document, schema, next) ->
These will override internal wongo middleware, but won't override locally defined middleware.
wongo.options.prune = false
wongo.options.validate = (document, schema, callback) ->
# implement your own validate method for all your schemas
Plugins work similar to mongoose, though they aren't compatible, because the schema object will be different.
Here is an example of a plugin which adds createdOn and modifiedOn to the schema and also adds before middleware save functionality. Note, that unshift is used to apply the middleware before validation.
# Addes a modifiedOn and createdOn timestamp to a schema and updates beforeSave.
module.exports = (schema, options) ->
# add fields to schema
schema.fields.createdOn = {type: Date, required: true}
schema.fields.modifiedOn = {type: Date, required: true}
# add beforeSave middleware
schema.middleware.beforeSave.unshift (document, schema, callback) ->
document.createdOn ?= new Date()
document.modifiedOn = new Date()
callback()
Want more examples? Check out the tests folder or just fill out an issue and ask.
This library was created because I was annoyed by the little things in mongoosejs.
Disclaimer: Before I get into the annoyances, mongoosejs is a terrific library. Nothing really comes close to it in terms of feature set, so the point of this project is not to reinvite the wheel, but to make it fit on my car. If you're driving a truck, you shouldn't use this library.
I use mocha. So, you should be able to run the 'mocha' command in the project folder and be done. However, you will need to add a db_config.json file that has the db_config.url parameter in it. This file is not committed to git for obvious reasons.
Here is a format you can use:
test/db_config.json
{
"url": "mongodb://{username}:{password}@{host}:{port}/{db}"
}
FAQs
A simple ODM for mongodb
The npm package wongo receives a total of 1 weekly downloads. As such, wongo popularity was classified as not popular.
We found that wongo demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
Research
Security News
Malicious npm packages posing as developer tools target macOS Cursor IDE users, stealing credentials and modifying files to gain persistent backdoor access.