Mongodb text search in R programming

0 votes

I created a MongoDB text index using R programming.

library(mongolite)
library(jsonlite)
  mn <- mongo(collection = "collname", db = "dbname", url = "mongodb://localhost:27017" )

mn$index(toJSON(list("title" = "text"), auto_unbox = TRUE))

I am trying to do MongoDB text search in R for the below code.

 mn$find(toJSON(list("$text" = list("$search" = "STORAGE")), auto_unbox = TRUE))

But, I got an output as "data frame with 0 columns and 0 rows".

Nov 2, 2018 in Data Analytics by Ali
• 10,440 points
113 views

1 answer to this question.

0 votes

this example works for me

library(mongolite)
m <- mongo(db = "mtcars", collection = "mtcars")
m$insert(mtcars)
m$index('{"_row":"text"}')
m$find( '{"$text":{"$search":"Mazda"} }')
# mpg cyl disp  hp drat    wt  qsec vs am gear carb
# Mazda RX4 Wag  21   6  160 110  3.9 2.875 17.02  0  1    4    4
# Mazda RX4      21   6  160 110  3.9 2.620 16.46  0  1    4    4

Similarly, constructing the JSON query from a list also works

m$find( toJSON(list("$text" = list("$search" = "Mazda") ), auto_unbox = T) )
# mpg cyl disp  hp drat    wt  qsec vs am gear carb
# Mazda RX4 Wag  21   6  160 110  3.9 2.875 17.02  0  1    4    4
# Mazda RX4      21   6  160 110  3.9 2.620 16.46  0  1    4    4
answered Nov 2, 2018 by Maverick
• 10,040 points

Related Questions In Data Analytics

0 votes
3 answers

How to write lines to a text file in R?

sink("outfile.txt") cat("hello") cat("\n" ...READ MORE

answered May 24 in Data Analytics by anonymous
2,793 views
0 votes
2 answers

What are the rules to define a variable name in R programming language?

The same rules almost follow for all ...READ MORE

answered Aug 26 in Data Analytics by anonymous
• 32,260 points
119 views
0 votes
1 answer

Remove NA values from the output in R programming

Edit your code: columnmean <- function(x, removeNA = ...READ MORE

answered Oct 31, 2018 in Data Analytics by Kalgi
• 45,800 points
52 views
0 votes
1 answer

"no applicable method" Error in r programming

This is caused by using an object-oriented ...READ MORE

answered Oct 31, 2018 in Data Analytics by Kalgi
• 45,800 points
118 views
0 votes
1 answer

Hadoop MapReduce vs MongoDB MapReduce

Hadoop vs MongoDB MR: 1) Hadoop's MR can ...READ MORE

answered Mar 26, 2018 in Big Data Hadoop by nitinrawat895
• 10,760 points
214 views
0 votes
1 answer

How can we send data from MongoDB to Hadoop?

The MongoDB Connector for Hadoop reads data ...READ MORE

answered Mar 26, 2018 in Big Data Hadoop by nitinrawat895
• 10,760 points
182 views
0 votes
1 answer

By using dpylr package sum of multiple columns

Basically here we are making an equation ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,720 points
124 views
0 votes
1 answer

How to convert a text mining termDocumentMatrix into excel or csv in R?

By assuming that all the values are ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,720 points
174 views
0 votes
1 answer

Difference between factor and as.factor in R programming

Hey @Ali, as.factor is a wrapper for ...READ MORE

answered Oct 29, 2018 in Data Analytics by Maverick
• 10,040 points
519 views
0 votes
1 answer

What is active binding in R programming

Active bindings in R are much like ...READ MORE

answered Oct 30, 2018 in Data Analytics by Maverick
• 10,040 points
43 views