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
- Collection
- new Collection(nameOrExisting, options)
- instance
- .collection ⇒
Mongo.Collection.<T>
- .allow() ⇒
Boolean
- .deny() ⇒
Boolean
- .rawCollection() ⇒
Mongo.Collection
- .rawDatabase() ⇒
Mongo.Db
- .insert(doc) ⇒
Observable.<string>
- .remove(selector) ⇒
Observable.<Number>
- .update(selector, modifier, options) ⇒
Observable.<Number>
- .upsert(selector, modifier, options) ⇒
Observable.<{numberAffected, insertedId}>
- .find(selector, options) ⇒
ObservableCursor.<T>
- .findOne(selector, options) ⇒
any
- .collection ⇒
- inner
- ~MongoQueryOptions :
Object
- ~MongoQuerySelector :
Mongo.Selector
|Mongo.ObjectID
|string
- ~MongoUpsertOptions :
Object
- ~MongoUpdateOptions :
Object
- ~MongoQueryOptions :
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. |
Returns the Mongo.Collection object that wrapped with the MongoObservable.Collection.
Kind: instance property of Collection
Returns: Mongo.Collection.<T>
- The Collection instance
Allow users to write directly to this collection from client code, subject to limitations you define.
Kind: instance method of Collection
Override allow rules.
Kind: instance method of 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
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
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. |
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 |
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 |
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. |
Method has the same notation as Mongo.Collection.find, only returns Observable.
Kind: instance method of Collection
Returns: ObservableCursor.<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});
}
}
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. |
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. |
A MongoDB query selector representation.
Kind: inner typedef of Collection
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). |
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. |