作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我可以说我是 JS 新手,但掌握了一切是如何工作的 - 但我最近尝试跳入 meteor ,它似乎只是删除了我难以理解的大部分快捷方式代码。
一旦 meteor 数据库达到一定数量的项目(在本例中为 100),我会尝试清空 meteor 数据库的前半部分。我只有:
var printOut = MongoDatabase.find().count();
if (printOut > 100) {
//delete first 50 entries of the 100 items
}
提前谢谢
最佳答案
首先找到 CreationDate 的截止日期,然后删除该日期之前的所有内容:
if (MongoDatabase.find().count() > 100){
cutoff = MongoDatabase.find({}, {fields: {CreationDate: 1, _id: 0}, sort: {CreationDate: -1 }, limit: 50}).fetch().pop().CreationDate
MongoDatabase.remove({CreationDate: {$lt: cutoff}})
}
这将在服务器上运行,但如果您尝试直接在客户端上执行此操作,您将收到以下错误:
"Not permitted. Untrusted code may only remove documents by ID. [403]"
因此,如果您需要从客户端触发此操作,使用 Meteor.Method 将是最好的方法。
关于javascript - 在一定数量后清空 Meteor 数据库/集合?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32584871/
我正在尝试开发右边框/Angular 具有特定 Angular (30°) 的表格。我见过一些类似的解决方案,但它们都无法在一定程度上发挥作用。如果我想从 30° 改变到 20°,我不想花太多力气。
我是一名优秀的程序员,十分优秀!