[CSHARP-1440] Is there option to run javascript from c# except eval Created: 08/Oct/15  Updated: 05/Apr/19  Resolved: 08/Oct/15

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: rajesh Assignee: Unassigned
Resolution: Done Votes: 0
Labels: question
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Hello,

Is there other option to run javascript which might contains multiple mapreduce? and return list of bsondocument ?

I tried eval to run but through error and showing map reduce not supported in eval.

I want to run following script from c# and get result.

------------------------------
db.services_providers.drop();
var servicemap = function (){
emit(this._id,

{providers:[],serviceName:this.serviceName}

)
}

var serviceProviderMap = function(){
var self=this;
this.services.forEach(function(data){
var p= new Array();
p.push(

{providerName:self.providerName,providerID:self._id}

)
emit(data,

{providers:p,serviceName:null}

);
});
}

var r = function(key, values){
var result=

{ serviceName:"", providers:[] }

values.forEach(function(value) {
if(value.serviceName!=null)

{ result.serviceName=value.serviceName }

if(value.providers!=null )

{ result.providers = result.providers.concat(value.providers); }

});
return result;
}

var a=db.services.mapReduce(servicemap, r, {out: {reduce : 'services_providers'}});

var b =db.serviceProviders.mapReduce(serviceProviderMap, r, {out: {reduce : 'services_providers'}});

db.services_providers.aggregate([

{ "$unwind":"$value.providers" }

,
{
'$project':

{ '_id':0, 'serviceID':'$_id', 'serviceName':'$value.serviceName', 'providerName':'$value.providers.providerName', 'providerID':'$value.providers.providerID' }


}
]);

------------------------------------

this script run properly in mongo command prompt. and showing result.



 Comments   
Comment by Craig Wilson [ 08/Oct/15 ]

Hi Rajesh,

The MongoDB user group is a much better place to ask these types of questions: https://groups.google.com/forum/#!forum/mongodb-user. We use JIRA for bug tracking and feature requests.

To answer your question, no. The .NET driver cannot be used to run shell commands. You'll need to rewrite your script to use the .NET driver.

Craig

Generated at Wed Feb 07 21:39:37 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.