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,290 points
34 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,000 points

Related Questions In Data Analytics

0 votes
1 answer

How to write lines to a text file in R?

It is easy and simple: fileConn<-file("abc.txt") writeLines(c("H ...READ MORE

answered Apr 16, 2018 in Data Analytics by DeepCoder786
• 1,700 points
527 views
0 votes
1 answer

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

A variable name in R programming language ...READ MORE

answered Sep 7, 2018 in Data Analytics by zombie
• 3,690 points
58 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
• 35,750 points
20 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
• 35,750 points
30 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
• 9,030 points
89 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
• 9,030 points
30 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,700 points
23 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,700 points
60 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,000 points
18 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,000 points
13 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.