API Docs for:
Show:

MongoCollection Class

Module: ringo-mongodb

MongoCollection

Constructor

MongoCollection

(
  • Collection
)

Parameters:

  • Collection Object

Methods

count

(
  • [query]
)
Number

Returns the number of documents in this collection

Parameters:

  • [query] Object optional

    query to match

Returns:

Number: number of documents

drop

()

Drops (deletes) this collection. Use with care.

dropIndex

(
  • obj
)

Drops an index from this collection

Parameters:

  • obj Object | String

    keys or name of the index to drop

dropIndexes

()

Drops all indices from this collection.

ensureIndex

(
  • keys
  • [options]
)
MongoCursor

Creates an index on a set of fields, if one does not already exist. See official documentation for available options.

Parameters:

  • keys Object

    an object with a key set of the fields desired for the index

  • [options] Object optional

    options for the index (name, unique, etc)

Returns:

MongoCursor: a cursor to iterate over results

find

(
  • [query]
  • [projection]
)
MongoCursor

Queries for an object in this collection.

Parameters:

  • [query] Object optional

    object for which to search

  • [projection] Object | Array optional

    Fields to return

Returns:

MongoCursor: a cursor to iterate over results

findOne

(
  • [query]
  • [projection]
  • [orderBy]
)
MongoDocument

Returns a single object from this collection.

Parameters:

  • [query] Object optional

    The query object or a valid ID object

  • [projection] Object | Array optional

    Fields to return

  • [orderBy] Object | Array optional

    fields to order by

Returns:

MongoDocument: the object found, or null if no such object exists

getIndexInfo

() Object

Return a list of the indexes for this collection. Each object in the list is the "info document" from MongoDB

Returns:

Object: list of index documents

insert

(
  • obj
)

Saves document(s) to the database. If doc doesn't have an _id, one will be added you can get the _id that was added from doc after the insert

Parameters:

  • obj Object | Array

    Document or array of documents to save

isCapped

() Boolean

Returns:

Boolean: Returns whether or not this is a capped collection

remove

(
  • query
)

Removes objects from the database collection.

Parameters:

  • query Object

    the object that documents to be removed must match

save

(
  • obj
)

Saves an object to this collection (does insert or update based on the object _id).

Parameters:

  • obj Object

    Document to save (will add _id field if needed)

update

(
  • query
  • obj
)

Performs an update operation.

Parameters:

  • query Object

    search query for old object to update

  • obj Object

    object with which to update query

Example:

 var col = mongo.connect().getDB('myDatabase').getCollection('myCollection');
 col.update( { item: "book", qty: { $gt: 5 } }, { $set: { x: 6 }, $inc: { y: 5} } );

Properties

name

String

Database name