Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Simple MongoDB driver for Node.js with jQuery like syntax.

License

NotificationsYou must be signed in to change notification settings

amark/mongous

Repository files navigation

Mongous, for humongous, is a simple and blazing fast MongoDB driver that uses a jQuery like syntax.

How it works

var $ = require("mongous").Mongous;$("database.collection").save({my:"value"});$("database.collection").find({},function(r){console.log(r);});

Done. App development has never felt as close to the shell as this! Making it a breeze to grab'n'store anything anywhere in your code without the nasty hassle of connections, collections, and cascading callbacks.

Database & Collections

  • db('Database.Collection')
    • Database is the name of your database
    • Collection is the name of your collection
    • Examples
      • db('blog.post')
      • db('blog.post.body')

Commands

  • Updatedb('blog.post').update(find, update, ...)
    • findis the object you want to find.
    • updateis what you want to update find with.
    • ...
      • { upsert: true, multi: false }
      • true, true
  • Savedb('blog.post').save(what)
    • whatis the object to be updated or created.
  • Insertdb('blog.post').insert(what...)
    • whatis an object to be created.is an array of objects to be created.
    • Examples
      • db('blog.post').save({hello: 'world'})
      • db('blog.post').save([{hello: 'world'}, {foo: 'bar'}])
      • db('blog.post').save({hello: 'world'}, {foo: 'bar'})
  • Removedb('blog.post').remove(what, ...)
    • what is the object to be removed.
    • ...true for atomic.
  • Finddb('blog.users').find(..., function(reply){ })
    • replyis the reply from MongoDB.
    • reply.documentsare the documents that you found from MongoDB.
    • ...
      params are filtered by type
      • Objects
        • first objectis what you want to find.
        • second objectare fields you want
          Ex:{ name: 1, age: 1 }
        • third objectis any of the following options:
          { lim: x, skip: y, sort:{age: 1} }
      • Numbers
        • first numberis the limit (return all if not specified)
        • second numberis the skip
    • Examples
      • db('blog.users').find(5, function(reply){ })
        reply.documents is the first 5 documents,
      • db('blog.users').find(5, {age: 23}, function(reply){ })
        with age of 23,
      • db('blog.users').find({age: 27}, 5, {name: 1}, function(reply){ })
        and a name.
      • db('blog.users').find(5, {age: 27}, {name: 1}, {lim: 10}, function(reply){ })
        is the same as the previous example, except the limit is 10 instead of 5.
      • db('blog.users').find(5, function(reply){ }, 2)
        reply.documents skips the first 2 documents and is the next 3 documents.
      • db('blog.users').find(function(reply){ }, {age: 25}, {}, {limit: 5, skip: 2})
        is the same as the previous example except only of doucments with the age of 25.
      • db('blog.users').find({}, {}, {sort: {age: -1}}, function(reply){ })
        reply.documents is sorted by age in a decsending (acsending while it is {age:1} ) order.
  • Operationsdb('blog.$cmd').find(command,1)
    • commandis the database operation command you want to perform.
    • Exampledb('blog.$cmd').find({drop:"users"},1)
      drops the users collection, deleting it.
  • Authenticationdb('blog.$cmd').auth(username,password,callback)
    • username, password
      username and password of the 'blog' database
    • callback
      the callback function when authentication is finished.
    • Example
      • db('blog.$cmd').auth('user','pass',function(reply){})
  • Opendb().open(host,port)
    • Only necessary to call if you explicitly want a different host and port, elsewise it lazy opens.

Mongous is a reduction ('less is more') of node-mongodb-driver by Christian Kvalheim.

About

Simple MongoDB driver for Node.js with jQuery like syntax.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp