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 localcollection with all npm packages installed. Try it out:

var localcollection = require("localcollection")

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

localcollection v0.0.3

MongoDB Query Style Array Filtering and Modifying


A Sift.JS wrapper that adds array modification and MongoDB collection-like instantiation for easy access to collections.

MongoDB inspired array filtering

For extended documentation, checkout MongoDB's Docs and Sift.JS


npm install localcollection --save

var localCollection = require('localcollection');

var Collection = new localCollection( YOUR_ARRAY/OBJECT );

Node.js Examples

var localCollection = require('localcollection');

var someArray = [{id: 1}, {id:2}, {id:3}];

var SomeArray = new localCollection(someArray);

// Find
// [ {id:2} ]

// FindOne
// {id:2}

// Remove
// [ {id:1}, {id:3} ]

// Count
// 1

// Update
SomeArray.update({id:3}, function(ob){ob.magic = true});
// [ {id:1}, {id:3, magic:true} ]

// Insert
SomeArray.insert({yoman: 'guild'});
// [ {id:1}, {id:3, magic:true}, {yoman: 'guild'} ]

// FindAndModify
SomeArray.findAndModify({yoman:'guild'}, function(ob){ob.happiness = true});
// [ {yoman:'guild', happiness:true} ]

Sift Dependency

This package is a simple wrapper on Sift.js. For more information on functionality and features, see Sift.js

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