<div dir="ltr"><div class="gmail_default" style="font-family:'comic sans ms',sans-serif">Prezados,</div><div class="gmail_default" style="font-family:'comic sans ms',sans-serif"><br></div><div class="gmail_default" style="font-family:'comic sans ms',sans-serif">
Estou acessando um MongoDB remotamente utilizando o R. Gero uma consulta, porém, quando crio um data frame com a consulta ele está vazio, alguém sabe me dizer onde está o problema?. Estou começando a me inteirar sobre o MongoDB. Envio o log do programa...</div>
<div class="gmail_default" style="font-family:'comic sans ms',sans-serif"><br></div><div class="gmail_default" style="font-family:'comic sans ms',sans-serif">Desde já agradeço.</div><div class="gmail_default" style="font-family:'comic sans ms',sans-serif">
<br></div><div class="gmail_default"><div class="gmail_default"><font face="comic sans ms, sans-serif">> library(rmongodb)</font></div><div class="gmail_default"><font face="comic sans ms, sans-serif">> </font></div>
<div class="gmail_default"><font face="comic sans ms, sans-serif">> # parâmetros</font></div><div class="gmail_default"><font face="comic sans ms, sans-serif">> host <- "xxxx"</font></div><div class="gmail_default">
<font face="comic sans ms, sans-serif">> username <- "xxx"</font></div><div class="gmail_default"><font face="comic sans ms, sans-serif">> password <- "xxxx"</font></div><div class="gmail_default">
<font face="comic sans ms, sans-serif">> db <- "censo2010"</font></div><div class="gmail_default"><font face="comic sans ms, sans-serif">> </font></div><div class="gmail_default"><font face="comic sans ms, sans-serif">> #conectando a base</font></div>
<div class="gmail_default"><font face="comic sans ms, sans-serif">> teste <- mongo.create(db="censo2010", host="xxxx", username="xxxx",password="xxxx")</font></div><div class="gmail_default">
<font face="comic sans ms, sans-serif">> </font></div><div class="gmail_default"><font face="comic sans ms, sans-serif">> #Obtendo a lista de bancos no MongoDBserver</font></div><div class="gmail_default"><font face="comic sans ms, sans-serif">> print(mongo.get.databases(teste))</font></div>
<div class="gmail_default"><font face="comic sans ms, sans-serif">NULL</font></div><div class="gmail_default"><font face="comic sans ms, sans-serif">> </font></div><div class="gmail_default"><font face="comic sans ms, sans-serif">> #obtendo a lista de collection</font></div>
<div class="gmail_default"><font face="comic sans ms, sans-serif">> print(mongo.get.database.collections(teste, db))</font></div><div class="gmail_default"><font face="comic sans ms, sans-serif">[1] "censo2010.censo2010"</font></div>
<div class="gmail_default"><font face="comic sans ms, sans-serif">> </font></div><div class="gmail_default"><font face="comic sans ms, sans-serif">> #Returns a fresh mongo.bson.buffer object ready to have data appended onto it </font></div>
<div class="gmail_default"><font face="comic sans ms, sans-serif">> buf <- mongo.bson.buffer.create()</font></div><div class="gmail_default"><font face="comic sans ms, sans-serif">> </font></div><div class="gmail_default">
<font face="comic sans ms, sans-serif">> #Start a subobject within a mongo.bson.buffer</font></div><div class="gmail_default"><font face="comic sans ms, sans-serif">> mongo.bson.buffer.start.object(buf, 'V0001')</font></div>
<div class="gmail_default"><font face="comic sans ms, sans-serif">[1] TRUE</font></div><div class="gmail_default"><font face="comic sans ms, sans-serif">> #Append a name/value pair into a mongo.bson.buffer</font></div>
<div class="gmail_default"><font face="comic sans ms, sans-serif">> mongo.bson.buffer.append(buf, '$eq', '11')</font></div><div class="gmail_default"><font face="comic sans ms, sans-serif">[1] TRUE</font></div>
<div class="gmail_default"><font face="comic sans ms, sans-serif">> #Finish a subobject or array within a mongo.bson.buffer</font></div><div class="gmail_default"><font face="comic sans ms, sans-serif">> mongo.bson.buffer.finish.object(buf)</font></div>
<div class="gmail_default"><font face="comic sans ms, sans-serif">[1] TRUE</font></div><div class="gmail_default"><font face="comic sans ms, sans-serif">> </font></div><div class="gmail_default"><font face="comic sans ms, sans-serif">> #Convert a mongo.bson.buffer object to a mongo.bson object</font></div>
<div class="gmail_default"><font face="comic sans ms, sans-serif">> query <- mongo.bson.from.buffer(buf)</font></div><div class="gmail_default"><font face="comic sans ms, sans-serif">> </font></div><div class="gmail_default">
<font face="comic sans ms, sans-serif">> #Find records in a collection</font></div><div class="gmail_default"><font face="comic sans ms, sans-serif">> cur <- mongo.find(teste, 'censo2010.censo2010', query = query)</font></div>
<div class="gmail_default"><font face="comic sans ms, sans-serif">> </font></div><div class="gmail_default"><font face="comic sans ms, sans-serif">> V0001 <- NULL</font></div><div class="gmail_default"><font face="comic sans ms, sans-serif">> while (mongo.cursor.next(cur)) {</font></div>
<div class="gmail_default"><font face="comic sans ms, sans-serif">+ value <- mongo.cursor.value(cur)</font></div><div class="gmail_default"><font face="comic sans ms, sans-serif">+ V0001 <- rbind(V0001, mongo.bson.value(value, 'V0001'))</font></div>
<div class="gmail_default"><font face="comic sans ms, sans-serif">+ }</font></div><div class="gmail_default"><font face="comic sans ms, sans-serif">> data2 <- data.frame(V0001=V0001) # AQUI O DATAFRAME ESTÁ VAZIO</font></div>
</div><div><br></div>-- <br><div dir="ltr"><span style="font-family:'comic sans ms',sans-serif">Savano Pereira</span><div><span style="font-family:'comic sans ms',sans-serif">TEL: 21 8771-9063</span></div>
<div><br></div><div><br></div></div>
</div>