Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including submongojs with all npm packages installed. Try it out:

var submongojs = require("submongojs")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

submongojs v0.1.4

sub-sections of mongodb databases with mongojs


sub-sections of mongodb databases with mongojs

build status


Ok. So let's say you're building a personal finance app for many customers, two of which are Alice and Bob. You have to be very careful not to show Alice's expenses on Bob's account, so you MUST always remember to filter by account_id or such. Or you can use this module as following.

var mongojs = require('mongojs');
var submongojs = require('submongojs');

var db = mongojs('myapp', ['expenses']);

// ...

var accountId = getIdSomehow();
var expenses = submongojs(db.expenses, accountId, 'account_id');

// Then from here on, we just use the mongojs API

expenses.find({active: true}).limit(10, function(err, exps) {


npm install submongojs


The module is just one function.

submongojs(collection, idvalue, [idFieldName])

Then afterwards, you just need to use the mongojs collection API.




RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free