[CSHARP-1740] Nesting external json queries and execute them Created: 09/Aug/16  Updated: 17/Aug/16  Resolved: 17/Aug/16

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

Type: New Feature Priority: Major - P3
Reporter: Lanfranco Giuseppe Morini Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows



 Description   

We are trying to nest a jsonquery (maybe read from an external text file) in c# code.
We were using
var query = MongoDB.Bson.Serialization.BsonSerializer.Deserialize<BsonDocument>(jsonString)
and then we were used to invoke QueryComplete to execute the query.
In the last version of C# driver this way is deprecated (there is not QueryComplete anymore).

Is there a new way to obtain the same results (that is writing a json\javascript query, put it in an external repository and then load and execute it when needed)?
Please keep in mind that the application doesn't know what is the collection nor the aggregation pipeline in the query...

Thanks a lot and best regards,
Lanfranco



 Comments   
Comment by Craig Wilson [ 17/Aug/16 ]

Lanfranco,

jsonString != javascriptString. You are essentially asking us to implement the Javascript language. We will not be doing that. Our purpose isn't to provide a shell interface inside .NET, but rather enable communicating with the server in a way typical for .NET developers.

I'm going to close this as won't fix.

Craig

Comment by Lanfranco Morini [ 17/Aug/16 ]

UPDATE
"in Legacy Driver there was MongoDatabase.RunCommand(string) method: what did class\method substitute it?": RunCommand still exists (method of IMongoDatabase interface), but it seems that it doesn't allow to run "shell" command such as "find" or "aggregate"...

Comment by Lanfranco Morini [ 12/Aug/16 ]

Hi Craig:
I'd need more abstraction.
In jsonString variable I'd like to have a full query (i.e.

"db.orders.find({_id:"xvbko"})" 

or

"db.orders.aggregate([
{$project :{
     "year":{$year:"$line.TMS_CREAZIONE.DateTime"}, 
     "month":{$month:"$line.TMS_CREAZIONE.DateTime"}, 
     "day":{$dayOfMonth:"$line.TMS_CREAZIONE.DateTime"},
     "hour":{$hour:"$line.TMS_CREAZIONE.DateTime"},
     "minutes":{$minute:"$line.TMS_CREAZIONE.DateTime"},
     "seconds":{$second:"$line.TMS_CREAZIONE.DateTime"},
     "timestamp":{$divide:["$line.TMS_CREAZIONE.Ticks",1000]},         
     "exchange":"$line.COD_MERCATO",
     "ISIN":"$line.TITOLO"
     }},
{$match: {$and:[
         {"exchange":"ETLX"},
         {"year":2015},{"month":06},
         {"day":29},
         {"ISIN":"IT0004806730"} ]}},
{$sort:{"hour":1,"minutes":1,"seconds":1}}]))") 

without have to care if it contains a "find" or an "aggregate", or "orders" collection or "trades" collection.
The example that you wrote expects that you know what's the collection and if you perform a find or an aggregate...

Summarizing, in Legacy Driver there was MongoDatabase.RunCommand(string) method: what did class\method substitute it?

Best regards,
Lanfranco

Comment by Craig Wilson [ 09/Aug/16 ]

You can simply pass the json string to the Find method. I don't know what you've tried, but it should be simple enough.

var results = collection.Find(jsonString).ToList();

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