I find a lot of examples with js queries for Mongodb. For example the following code were it is find duplicates in the collection :
db.collection.aggregate(
{"$group" : { "_id": "$name", "count": { "$sum": 1 } } },
{"$match": {"_id" :{ "$ne" : null } , "count" : {"$gt": 1} } },
{"$project": {"name" : "$_id", "_id" : 0} }
)
I understand that equivalents is something like the following:
var query = collection.Aggregate().Match(some lambda function).Group(some lambda funtion) });
But I do not see who to translate-map each statement to lambda function.
Can someone explain how to translate-map can be done with an example?
Thank you for your time.
EDIT:
I pass some example code to be more spesific:
My Main
static void Main(string[] args)
{
MongoCRUD db = new MongoCRUD("MyDB");
db.FindDouplicateValues<GlobalUrbanPoint>("MyColection");
}
My model class:
public class GlobalUrbanPoint
{
[BsonId]
public ObjectId Id{ get; set; }
public string NAME { get; set; }
public int LATLONGID { get; set; }
public double LATITUDE { get; set; }
public double LONGITUDE { get; set; }
}
And for the operation i use MongoCRUD
public class MongoCRUD
{
private IMongoDatabase db;
// Connect to DataBase
public MongoCRUD(string database)
{
var client = new MongoClient();
db = client.GetDatabase(database);
}
public void FindDouplicateValues<T>(string table) where T : GlobalUrbanPoint
{
var collection = db.GetCollection<T>(table);
//Find the duplicates by LATLONGID. My syntax is wrong
var query = collection.Aggregate().Group(t => t.LATLONGID ).Match(g=>g.Count()>1);
}
}