Tony
Tony

Reputation: 17647

DocumentDB not working with simple MongoDB commands

I am considering DocumentDB, specially for the ability to bring my MongoDB code to work with it. DocumentDB is very fast and affordable, but I am having some difficulty:

I have this code that works on MongoDB:

var categoriesList = await Pessoa.Distinct<string>("Enderecos.Cidade", new BsonDocument()).ToListAsync();

This Exception happens:

MongoCommandException: Command distinct failed: Command is not supported.

On this code:

var cidades = Pedido.AsQueryable().Where(d => d.DocType == new Pedido().DocType)
                 .GroupBy(p => p.Cliente.Enderecos[0].Cidade)
                 .ToList();

It gives this exception:

MongoDB.Driver.MongoCommandException: 'Command aggregate failed: '$group' is not supported.'

What can I do to make it work on DocumentDB? Is there any simple equivalent code I can do to have this feature? Distinct / Group by on DocumentDB?

DocumentDB must support this. I will probably stay on Mongo until they release these features.

Upvotes: 0

Views: 742

Answers (1)

Mimi Gentz
Mimi Gentz

Reputation: 1658

Tony-

Support for GroupBy is coming. In the mean time, here are a few ways you can implement the same functionality:

  • By enumerating the distinct values, then aggregating them one by one
  • By using a streaming pattern on top of DocumentDB’s change feed (materialize the aggregates on write)
  • By using Spark + DocumentDB

Upvotes: 2

Related Questions