Urigo / meteor-rxjs

Exposing Mongo Cursor as RxJS Observable

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

collection.insert not working when using SimpleSchema

veeramarni opened this issue · comments

I was testing insert and tried to perform subscribe to do some async action. But when using SimpleSchema it won't work but without it works.

Is this a limitation or bug?

const boxes = new Mongo.Collection('boxes');

boxes.schema = new SimpleSchema({
  _id: {
    type: String,
  },
  name: {
    type: String,
  },
  description: {
    type: String,
    optional: true,
  },
  lang: {
    type: String,
  }
}
boxes.attachSchema(boxes.schema);
const Boxes = new MongoObservable.Collection(boxes);

Boxes
      .collection #-- without collection it is not inserting.
      .insert({
        name,
        description,
        lang,
      }, { validate: true });

I would like to do something

Boxes.insert(doc).subscribe( str => console.log(str));

I have noticed subscribe working only when there isn't any error in the insert. Otherwise, I don't even capture in the error function.

insert implemented as Observable, and you need to perform subscribe in order to execute the actual insert.
Please try:

Boxes
      .insert({
        name,
        description,
        lang,
      }, { validate: true }).subscribe(() => { ... });

I'm using redux-observable in addition to meteor-rxjs, so I don't subscribe there.I have noticed issue when validation fails, it don't throw the error and also don't return anything.

@veeramarni, can you share a repository with an example?

Closing due to inactivity and cleanup.
Feel free to open a new issue if you are still affected.