简体   繁体   English

输出一组没有转发的随机推文mongodb

[英]Output a set of random tweets without retweets mongodb

goal: eliminate retweets RT while outputting a random set of tweets 目标:在输出随机一组推文的同时消除转发RT

The following code outputs 20 random tweets: 以下代码输出20条随机推文:

DBQuery.shellBatchSize = 20
db.mycollection.aggregate({$sample: {size: 20}}, {$project: {"_id": 0,"text": 1}})

The following code eliminates retweets: 以下代码消除了转发:

db.mycollection.find({text:{$nin:[/^RT /]}},{text:1, _id:0})

question: Is there a way to add text:{$nin:[/^RT /] to db.mycollection.aggregate code to eliminate retweets RT and generate a given number of random tweets? 问题:有没有一种方法可以在db.mycollection.aggregate代码中添加text:{$nin:[/^RT /]以消除转推RT并生成给定数量的随机转推? if not, what line of code will allow me to do so? 如果没有,那么哪一行代码可以允许我这样做?

Per Veeram的评论:

db.mycollection.aggregate({$match:{text:{$nin:[/^RT /]}}},{$sample: {size: 20}}, {$project: {"_id": 0,"text": 1}})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM