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
• 11,360 points
892 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,840 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, 2019 in Data Analytics by anonymous
19,077 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, 2019 in Data Analytics by anonymous
• 33,030 points
15,176 views
+1 vote
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
• 52,350 points
894 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
• 52,350 points
2,561 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
• 11,380 points
1,429 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 27, 2018 in Big Data Hadoop by nitinrawat895
• 11,380 points
2,120 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
2,265 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
1,962 views
+1 vote
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,840 points
4,895 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,840 points
1,500 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP