在Meteor中创建MongoDB上限集合

问题描述 投票:0回答:1

我是Meteor和MongoDB的新手。有人可以提供一个代码片段,用于在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);
mongodb meteor
1个回答
0
投票

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

meteor add accounts-password
© www.soinside.com 2019 - 2024. All rights reserved.