Skip to content

Unable to extract a BSON_CODE field from a document #18

@bdiegel

Description

@bdiegel

I'm trying to retrieve a stored function from 'system.js' and use it in mapReduce.

When I retrieve and print the document that defines the function it is correct. However, when I try to extract the 'value' field (BSON_CODE) the JavaScript code is lost in the conversion.

Document returned from database:

mongo.bson.print(result)
_id : 2 mapVarType
value : 13 BSON_CODE: function() {
if ( (this.doctype == "vcf_variant") &&
(typeof this.other.var_type != "undefined" ))
{
emit( this.other.var_type, 1);
}
}

Extract 'value' field (hm, looks empty?):

mongo.bson.value(result, "value")
[1] ""
attr(,"class")
[1] "mongo.code"

Looking at the structure, 'chr' is empty:

str(mongo.bson.value(result, "value"))
Class 'mongo.code' chr ""

It should look like this one.

js_function <- mongo.code.create( ' ' )
str(js_function)
Class 'mongo.code' chr "function () {if ( (this.doctype == "vcf_variant") && (typeof this.other.var_type != "undefined" )) {emit( this.other.var_ty"| truncated

I've tried a few different things, including converting the bson to a list first using 'mongo.bson.to.list(result)'. The results are the same, it is empty.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions