Problem returning array of strings instead of BsonDocument Mongodb c# driver Unwind

385 views Asked by At

I have got a class called Contact which has a field named Numbers and Numbers is a list of strings. I want to return a list containing all numbers in matched documents only. but it gives me an array of BsonDocuments. I need Just a List of numbers.

here is my query:

var query = await _context.ContactLists.Aggregate(new AggregateOptions { AllowDiskUse = true })
                    .Match(x => x.Id == id && x.CreatorId == user.GetUserId())
                    .Unwind(x => x.Numbers)
                    .Project(Builders<BsonDocument>.Projection.Include("Numbers").Exclude("_id"))
                    .ToListAsync();

it resturns :

[{{ "Numbers" : "989309910790" }}]

and I need :

["989309910790"]

I am not allowed to use Linq driver.

0

There are 0 answers