我从twitter收集了n个用户的关注者列表和好友列表,并将其存储在mongodb中。
以下是一份示例文件:
{
"_id": ObjectId("561d6f8986a0ea57e51ec95c"),
"status": "True",
"UserId": "1489245878",
"followers": [
"1566382441",
"1155774331"
],
"followersCount": 2,
"friendsCount": 5,
"friends": [
"1135511478",
"998082481",
"565321118",
"848123988",
"343334562"
]
}
我想知道我的收藏中是否有任何用户ID也在其他文档的关注者列表中。假设我们有用户“a”,现在我想知道用户“a”是否在同一集合中任何其他文档的关注者列表中。我不知道该怎么做。如果我们有,我想在跟随者列表中投影具有用户ID的文档的userid和_id。
答案 0 :(得分:0)
我猜您可以使用下面的聚合函数来获得此结果。
library(shiny)
library(dygraphs)
library(xts)
#------Importation des données contenues dans un .csv------
setwd("C:/Users") #attention,on ne peut pas faire créer à R un dossier, il faut le créer via windows
#----Importation données de qualité d'eau
TabSMP=read.csv2(file="Analyse R/MC1_MC2_SMP.csv",sep=";",dec=".",na.strings = "#N/A")
TabSMPMC1=read.csv2(file="Analyse R/MC1_SMP.csv",sep=";",dec=".",na.strings = "#N/A")
TabSMPMC2=read.csv2(file="Analyse R/MC2_SMP.csv",sep=";",dec=".",na.strings = "#N/A")
TabMC1Manu=read.csv2(file="Analyse R/MC1_Manu.csv",sep=";",dec=".",na.strings = "#N/A")
TabMC2Manu=read.csv2(file="Analyse R/MC2_Manu.csv",sep=";",dec=".",na.strings = "#N/A")
TabMC3Manu=read.csv2(file="Analyse R/MC3_Manu.csv",sep=";",dec=".",na.strings = "#N/A")
TabMC4Manu=read.csv2(file="Analyse R/MC4_Manu.csv",sep=";",dec=".",na.strings = "#N/A")
#-----Attribution du format de date et heure à la colonne date/heure pour chaque tableau------
TabSMP$DateHeure=as.POSIXct(TabSMP$DateHeure,format="%d/%m/%Y %H:%M")
TabSMPMC1$DateHeure=as.POSIXct(TabSMP$DateHeure,format="%d/%m/%Y %H:%M")
TabSMPMC2$DateHeure=as.POSIXct(TabSMP$DateHeure,format="%d/%m/%Y %H:%M")
TabMC1Manu$DateHeure=as.POSIXct(TabMC1Manu$Date,format="%d/%m/%Y %H:%M")
TabMC2Manu$DateHeure=as.POSIXct(TabMC2Manu$Date,format="%d/%m/%Y %H:%M")
TabMC3Manu$DateHeure=as.POSIXct(TabMC3Manu$Date,format="%d/%m/%Y %H:%M")
TabMC4Manu$DateHeure=as.POSIXct(TabMC4Manu$Date,format="%d/%m/%Y %H:%M")
#TabB5Manu$DateHeure=as.POSIXct(TabB5Manu$Date,format="%d/%m/%Y %H:%M")
ls.str()# vérification des reconnaissances par R des caractères numériques, textes, dates...
TabSMPMC1_xts_Temp <- xts(TabSMP$MC1_Temp,order.by=TabSMP$DateHeure,frequency=365)
TabSMPMC2_xts_Temp <- xts(TabSMP$MC2_Temp,order.by=TabSMP$DateHeure,frequency=365)
TabMC3Manu_xts_Temp <- xts(TabMC3Manu$MC3_Temp,order.by=TabMC3Manu$DateHeure,frequency=365)
TabMC4Manu_xts_Temp <- xts(TabMC4Manu$MC4_Temp,order.by=TabMC4Manu$DateHeure,frequency = 365)
Temperature <- cbind(TabSMPMC1_xts_Temp,TabSMPMC2_xts_Temp,TabMC3Manu_xts_Temp,TabMC4Manu_xts_Temp)
dygraph(Temperature,main="Evolution de la tempértaure") %>%
dyAxis("y", label = "°C ", valueRange = c(-1, 11)) %>%
dySeries("..1",label="MC1_Temp",strokeWidth=1.75) %>%
dySeries("..2",label="MC2_Temp",strokeWidth=1.75) %>%
dySeries("..3",label="MC3_Temp",pointSize=2.5) %>%
dySeries("..4",label="MC4_Temp",pointSize=2.5) %>%
dyOptions(colors = c("blue","orange","pink","green")) %>%
dyLegend(width=400) %>%
dyEvent(DebutVidange, "Ouverture Vanne de Fond", labelLoc = "top") %>%
dyEvent(FinVidange, "Fin Vidange", labelLoc = "top") %>%
dyShading(from =DebutVidange, to =FinVidange, color = "#F0F9FF") %>%
dyShading(from =DebutAssec, to =FinAssec, color = "#FFFFFF") %>%
dyRangeSelector()
我只使用您的数据样本。您可以在db.getCollection('your_collection").aggregate([
{
"$match": {
"followers": "1566382441"
}
},
{
"$project": {
"followers": 1
}
},
{
"$unwind": "$followers"
},
{
"$match": {
"followers": "1566382441"
}
},
{
"$group": {
"_id": "$followers",
"ids": {
"$addToSet": "$_id"
}
}
},
{
"$project": {
"userId": "$_id",
"ids": 1,
"_id": 0
}
}
])
的两个阶段中添加要尝试过滤的用户列表。看看这是否有帮助。