RMongo insert analytic result to db


#1

i am trying to learn Rmongo . i used Loan_prediction example. i import train and test to mongo db.
i am trying to train the model by using train data from mongodb. and after analysis and prediction i am trying to update the predicted result back to mongodb.

i am stuck with updating only Loan_status alone to the mongodb table loan_prediction-test which i imported
earlier.
please kindly help me on this.

test<-dbSelect(export,‘analytics.loan_prediction_test’)

fit <- randomForest(formula, data=train,importance=TRUE, ntree=38)
#colSums(is.na(test))
pred=predict(fit,test)
test$Loan_Status=pred

for( i in 1:nrow(test)){
row <- test[i,]
criteria <- mongo.bson.from.df(row)
objnew <- mongo.bson.from.df(row)
objnew$Loan_Status<-'Y’
mongo.update(mongo,‘analytics.loan_prediction_test’,
(criteria),
(objNew ),mongo.update.multi)
print(mongo.get.err(mongo))
}