jeroen / mongolite

Fast and Simple MongoDB Client for R
https://jeroen.github.io/mongolite/
286 stars 65 forks source link

Mongolite Map/Reduce getting Error #134

Closed psramkumar closed 6 years ago

psramkumar commented 6 years ago

Mongo Console it works fine as below

var _mapper = function(){emit(this._id, {user_id : this.user_id, name : this.user_name});}
var _reducer = function(id, docs) { return docs; } 
db.user.mapReduce(_mapper, _reducer, { "out": { "inline": 1 } });

in R console it is not working and showing the below Error **Error: Unimplemented BSON type 6**

here is the R Snippet

user_map<- dbs$mapreduce(
    map = 'function(){emit(this._id, {user_id : this.user_id,name : this.user_name});}',
    reduce = 'function (id, docs) { return docs; }' 
)
jeroen commented 6 years ago

Your database is probably corrupt. It returns BSON type 6 data which is undefined/deprecated.

psramkumar commented 6 years ago

thanks for your Quick answer, i tried the below three query with the fields involved in my MR and found no record.. if there any other way i could try ?

db.user.find({ _id: { $type: 6 } })
db.user.find({ user_name: { $type: 6 } })
db.user.find({ user_id: { $type: 6 } })

one more point to add i'm able to do full fetch on the same collection using dbs$find() from R Console

psramkumar commented 6 years ago

Resolved the issue by filtering out all Null values from results

user_map<- dbs$mapreduce(
    map = 'function(){emit(this._id, {user_id : this.user_id,name : this.user_name});}',
    reduce = 'function (id, docs) { return docs; }' ,
    query = '{ "status": "ACTIVE", "user_id": { "$ne": null }, "user_name": { "$ne": null } }' 
)
jeroen commented 6 years ago

Maybe you can use the aggregate function.

psramkumar commented 6 years ago

my use case is different, going with this way to avoid unwind and multiple pipes of grouping and so on

thanks :)