【问题标题】:Create MongoDB capped collections in Meteor在 Meteor 中创建 MongoDB 上限集合
【发布时间】: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)”的集合,效果很好

标签: mongodb meteor


【解决方案1】:

您的应用中可能没有安装任何“帐户”包。查看应用程序的 .meteor/packages 文件,查看是否存在任何以 accounts 开头的包(例如,accounts-password)。如果没有,请尝试在您的流星项目的根目录中运行以下命令:

meteor add accounts-password

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-03
    • 2011-12-15
    • 2018-08-24
    • 2015-10-16
    • 2016-01-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多