Coder Social home page Coder Social logo

shelly's Introduction

Shelly.js

What is it?

Make building queries and updating MongoDB documents in the Mongo shell much easier. Written in JS for MongoDB's JS Shell.

Why did you build it?

I just got tired of writing really difficult queries for updating a few records. I got tired of hitting the shell window width and flubbing bracket placement.

What can I do with it?

  • Build up queries with and_where, and_has
  • Easily set your scope, call .set('key', value), then save to make editing documents painless
  • Update documents like an ORM class
  • Pluck out values from ambiguaous paths .get('my.really.deep.path')

Example use..

Find a single record by id

Mongo

db.contacts.find({ _id : ObjectId('5489ea63c96a880167462784') })`

Shelly

var c = Shelly('contacts')
c.find('5489ea63c96a880167462784')

//or
c.first('5489ea63c96a880167462784')

Find records that have 'triggers' key

Mongo

db.contacts.find({ 'triggers' : { $exists : true } })

Shelly

var c = Shelly('contacts')
c.has('triggers')
c.each...

Updating a records

Mongo

db.contacts.update({ 'triggers.email' : { $exists : false } }, { 
	$set : { 'triggers.email' : true }
}, { $multi : true });

Shelly

var c = Shelly('contacts');
c.has('triggers.email', false);
c.set('triggers.email', true);
c.update({ multi : true });

Other Nice Stuff

Inspect your current state

var c = Shelly('contacts');
c.where(query)
c.and_where(query)

//what does that look like?
c.inspect()
//oh yeah!

get/set values out of objects

var c = Shelly('contacts')
c.where(query)
c.get()
c.forEach(function(contact){
	var path = 'meta.phones.mobile.0';
	var mobile = contact.get('meta.emails.mobile.0');
	mobile =  mobile ? myFormatter(mobile) : 'some other value';
	contact.set(path, mobile);
	contact.save();
});

Why no chaining?

Because this will be printed to the shell. If you know a way to mute this let me know!!

TODO

  • Support for and/or conjections with and_where or_where
  • Support building queries with other Shelly queries
  • map reduce, stuff
  • Easy join builder

Logo by Natalypaint and not part of license

shelly's People

Contributors

srhyne avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

kazuar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.