在Meteor MongoObservable

时间:2016-10-08 18:39:12

标签: mongodb meteor angular

所以,我按照angular2-meteor样板中的建议创建了集合:

export const BookCollection = new MongoObservable.Collection<Book>('books');

所以,如果我写这样的东西:

BookColletion.insert(..., callback_f);

我收到错误,第二个参数不存在。那么,我应该如何获得最后插入文档的ID?

2 个答案:

答案 0 :(得分:2)

我不确定MongoObservable是什么,也不确定<Book>语法是什么意思,但我怀疑你想要的是这样的:

export const BookCollection = new Mongo.Collection('books');
BookCollection.find().observe({
  added(document) {
    // document is the newly added document
  }
});

答案 1 :(得分:1)

您可以像这样获取插入的ID:

var insertedId = BookColletion.collection.insert();

如上所述here