0.2.6 • Published 8 years ago

mongoose-observables v0.2.6

Weekly downloads
57
License
MIT
Repository
github
Last release
8 years ago

mongoose-observables

npm install mongoose-observables --save

Getting started

var mongoose = require('mongoose');

Job = mongoose.model('Job', new mongoose.Schema({
    title: String
}));

model.Person = mongoose.model('Person', new mongoose.Schema({
    name: String,
    job: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'Job'
    }
}));

Create Job

var observables = require('mongoose-observables');

observables.creator
    .create(Job, {title: "developer"})
    .subscribe(job => console.log(job), err {
        throw err;
    });

Create Person with existing job

var observables = require('mongoose-observables');

observables.creator()
    .create(Person, {name: 'Octocat'}, [{name: 'job', data: observables.finder.findOne(Job, {title: "developer"})}])
    .subscribe(person => console.log(person), err {
        throw err;
    });

Create Person and job

var observables = require('mongoose-observables');

observables.creator()
    .create(Person, {name: 'Other Octocat'}, [{name: 'job', data: observables.creator.create(Job, {title: "firefighter"})}])
    .subscribe(person => console.log(person), err {
        throw err;
    });

Create 3 jobs

var observables = require('mongoose-observables');
var Rx = require('Rx');

var job1 = observables.creator.create(Job, {title: "developer"})
var job2 = observables.creator.create(Job, {title: "firefighter"})
var job3 = observables.creator.create(Job, {title: "teacher"})

Rx.Observable.forkJoin([job1, job2, job3]).subscribe(data => console.log(data), err => {
    throw err;
});

Find Person and populate job

var observables = require('mongoose-observables');

observables.finder
    .findOne(Person, {name: 'Octocat'}, null, {job: null})
    .subscribe(person => console.log(person), err {
        throw err;
    });

Find Person with only name and populate job with only title

var observables = require('mongoose-observables');

observables.finder
    .findOne(Person, {name: 'Octocat'}, "name -_id", {job: "title -_id"})
    .subscribe(person => console.log(person), err {
        throw err;
    });
0.2.6

8 years ago

0.2.5

8 years ago

0.2.4

8 years ago

0.2.3

8 years ago

0.2.2

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago

0.0.0

8 years ago