0
Salve galera!
I’m working with c# Mongodb . Net Driver, and there’s something I don’t understand in the queries, follow the example:
var dataBase = mongoClient.GetDatabase(dbName);
var transactionsColl = dataBase.GetCollection<BsonDocument>(transactionCollectionName);
var mongoSales = transactionsColl.Aggregate()
.Match(BsonDocument.Parse("{ 'saleDate': { $lte: ISODate('" + timeStamp.ToString("o") + "') } }"))
.Group(new BsonDocument { { "_id", "$saleId" }, { "_documentObjId", "$_id" } }).ToListAsync().Result;
In the grouping I have { "_id", "$saleId" }
and { "_documentObjId", "$_id" }
, the error is in the "_documentObjId"
, causes the following Exception:
{"Command aggregate failed: the group aggregate field '_documentObjId' must be defined as an expression inside an object."}
I had understood that I could put any name as property of the document, but the error is not so simple, including in "_id"
If I change to any other name from the same mistake, where do I make that definition?
Thanks!
Hello, I didn’t quite understand your question. But I believe you the error occurs is because you haven’t mapped the _documentObjId field anywhere. You’ve already made your move?
– Jhonathan
@Jhonathan, in short it’s this, I don’t understand where I can do this mapping, since _id I didn’t do the mapping either, but it works.
– rhgm
Have you created a class to handle objects? It would be better to use it instead of Bsondocument.
– Jhonathan
@Jhonathan I researched this before, but I abandoned it because of the performance, according to reports the performance falls a lot like this, and this service I’m creating will generate a data cube and so I need a lot of performance.
– rhgm
@Jhonathan , but if there’s no other way I’ll have to create a real class... But my curiosity about _id working without mapping will stay.
– rhgm
Good my tips are: Try to test this code on mongoDB, it may be that your aggregation is mounted wrong. Try removing (underline) from the documentObjId variable
– Jhonathan
@Jhonathan, I did as you said, made the same mistake.
– rhgm
Let’s go continue this discussion in chat.
– Jhonathan