I have the following code :
MongoClient m = new MongoClient();
var db = m.GetDatabase("PopupRentals");
string cmdDoc = (@"
db.Rentals.find({polygons:
{$geoIntersects:
{$geometry:{ 'type' : 'Point',
'coordinates' : [ 17.3734, 78.4738 ]
}
}
}
});");
var cmd = new JsonCommand<BsonDocument>(cmdDoc);
var res = db.RunCommand(cmd);
var result = db.GetCollection<RentalProperty>("Rentals");
I am using the standard mongodb v2 driver.
Once i execute the query i get the following error at about the
db.RunCommand(cmd);
System.FormatException: 'JSON reader was expecting a value but found 'db'.'
I have not the slightest clue why this is not working. It works great in Robo.
Your string cmdDoc
is not in proper format for using it the way you want to use it. Based on the MongoDB docs for the find
command, your string should look like this:
string cmdDoc = @"
{
find: "Rentals",
filter: {
polygons: {
$geoIntersects: {
$geometry: {
'type' : 'Point',
'coordinates' : [ 17.3734, 78.4738 ]
}
}
}
}
}"
or without all the extra whitespace for formatting:
string cmdDoc = @"{
find: "Rentals",
filter: { polygons: { $geoIntersects: { $geometry: { 'type' : 'Point', 'coordinates' : [ 17.3734, 78.4738 ] } } } }
}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With