Fork me on GitHub

Collection

A class represents a MongoDB collection in the client side, wrapped with RxJS Observables, so you can use it with your Angular 2 easier. The wrapper has the same API as Mongo.Collection, only the "find" method returns an ObservableCursor instead of regular Mongo.Cursor.

T is a generic type - should be used with the type of the objects inside the collection.

Kind: global class

new Collection(nameOrExisting, options)

Creates a new Mongo.Collection instance wrapped with Observable features.

Param Type Description
nameOrExisting String | Mongo.Collection The name of the collection. If null, creates an unmanaged (unsynchronized) local collection. If provided an instance of existing collection, will create a wrapper for the existing Mongo.Collection.
options ConstructorOptions Creation options.

collection.collection ⇒ Mongo.Collection.<T>

Returns the Mongo.Collection object that wrapped with the MongoObservable.Collection.

Kind: instance property of Collection
Returns: Mongo.Collection.<T> - The Collection instance

collection.allow() ⇒ Boolean

Allow users to write directly to this collection from client code, subject to limitations you define.

Kind: instance method of Collection

collection.deny() ⇒ Boolean

Override allow rules.

Kind: instance method of Collection

collection.rawCollection() ⇒ Mongo.Collection

Returns the Collection object corresponding to this collection from the npm mongodb driver module which is wrapped by Mongo.Collection.

Kind: instance method of Collection
Returns: Mongo.Collection - The Collection instance
See: rawCollection on Meteor documentation

collection.rawDatabase() ⇒ Mongo.Db

Returns the Db object corresponding to this collection's database connection from the npm mongodb driver module which is wrapped by Mongo.Collection.

Kind: instance method of Collection
Returns: Mongo.Db - The Db instance
See: rawDatabase on Meteor documentation

collection.insert(doc) ⇒ Observable.<string>

Insert a document in the collection.

Kind: instance method of Collection
Returns: Observable.<string> - Observable which completes with the inserted ObjectId
See: insert on Meteor documentation

Param Type Description
doc T The document to insert. May not yet have an _id attribute, in which case Meteor will generate one for you.

collection.remove(selector) ⇒ Observable.<Number>

Remove documents from the collection.

Kind: instance method of Collection
Returns: Observable.<Number> - Observable which completes with the number of affected rows
See: remove on Meteor documentation

Param Type Description
selector MongoQuerySelector Specifies which documents to modify

collection.update(selector, modifier, options) ⇒ Observable.<Number>

Modify one or more documents in the collection.

Kind: instance method of Collection
Returns: Observable.<Number> - Observable which completes with the number of affected rows
See: update on Meteor documentation

Param Type Description
selector MongoQuerySelector Specifies which documents to modify
modifier Modifier Specifies how to modify the documents
options MongoUpdateOptions Update options first argument and, if no error, the number of affected documents as the second

collection.upsert(selector, modifier, options) ⇒ Observable.<{numberAffected, insertedId}>

Finds the first document that matches the selector, as ordered by sort and skip options.

Kind: instance method of Collection
Returns: Observable.<{numberAffected, insertedId}> - Observable which completes with an Object that contain the keys numberAffected and insertedId.
See: upsert on Meteor documentation

Param Type Description
selector MongoQuerySelector Specifies which documents to modify
modifier Modifier Specifies how to modify the documents
options MongoUpsertOptions Upsert options first argument and, if no error, the number of affected documents as the second.

collection.find(selector, options) ⇒ ObservableCursor.<Array.<T>>

Method has the same notation as Mongo.Collection.find, only returns Observable.

Kind: instance method of Collection
Returns: ObservableCursor.<Array.<T>> - RxJS Observable wrapped with Meteor features.
See: find on Meteor documentation

Param Type Description
selector MongoQuerySelector A query describing the documents to find
options MongoQueryOptions Query options, such as sort, limit, etc.

Example (Using Angular2 Component)

 const MyCollection = MongoObservable.Collection("myCollection");

 class MyComponent  {
    private myData: ObservableCursor<any>;

    constructor() {
       this.myData = MyCollection.find({}, {limit: 10});
    }
 }

collection.findOne(selector, options) ⇒ any

Finds the first document that matches the selector, as ordered by sort and skip options.

Kind: instance method of Collection
Returns: any - The first object, or undefined in case of non-existing object.
See: findOne on Meteor documentation

Param Type Description
selector MongoQuerySelector A query describing the documents to find
options MongoQueryOptions Query options, such as sort, limit, etc.

Collection~MongoQueryOptions : Object

An options object for MongoDB queries.

Kind: inner typedef of Collection
Properties

Name Type Description
sort Object Sort order (default: natural order)
skip Number Number of results to skip at the beginning
fields Object Dictionary of fields to return or exclude.
reactive Boolean (Client only) Default true; pass false to disable reactivity
transform function Overrides transform on the Collection for this cursor. Pass null to disable transformation.

Collection~MongoQuerySelector : Mongo.Selector | Mongo.ObjectID | string

A MongoDB query selector representation.

Kind: inner typedef of Collection

Collection~MongoUpsertOptions : Object

A MongoDB query options for upsert action

Kind: inner typedef of Collection
Properties

Name Type Description
multi Boolean True to modify all matching documents; false to only modify one of the matching documents (the default).

Collection~MongoUpdateOptions : Object

A MongoDB query options for update action

Kind: inner typedef of Collection
Properties

Name Type Description
multi Boolean True to modify all matching documents;
upsert Boolean True to use upsert logic.