【发布时间】:2018-02-01 17:21:39
【问题描述】:
我是 Meteor 和 MongoDB 的新手。有人可以提供一个代码 sn-p 用于在 Meteor 中创建一个 MongoDB 上限集合(服务器端和客户端,如果需要在双方都完成)。这几天我一直在寻找这个。我找到了下面的代码,但是当我尝试它时,“Meteor.users”是未定义的。
import { Meteor } from 'meteor/meteor';
const db = Meteor.users.rawDatabase(); // get the underlying db class
const createCollection = Meteor.wrapAsync(db.createCollection, db); // wrap into futures/fibers
// now create a capped collection called bob:
try {
createCollection('bob', { capped: true, max: 100 });
} catch(error) {
// do something with the error
}
// All being well we can now connect to this collection with
const Bob = new Mongo.Collection('bob');
我也找到了以下代码,但是当我尝试时,我得到 -createCollection 不是函数:
var coll = new Meteor.Collection("myCollection");
coll._createCappedCollection(numBytes);
【问题讨论】:
-
它适用于其他收藏吗?如果 Meteor.users 的设置例程以您期望的方式使用 createCollection 调用,您是否检查过 GitHub 上的流星核心代码?
-
我没有检查这个方法是否适用于没有上限的集合。对于那些我一直在使用类似“coll = new Mongo.Collection(collectionName, idGenaration)”的集合,效果很好