MongoDb Group BY MAX date and get field from this document

Look my problen hehe. I don’t know how I can do it. There are a lot of assetState 1..n I would like do aggregation for get last asset state group by asset. Mongo collection : assetState [ { “lsd” : { “$id” : ObjectId(“lucas”) }, “stateDate” : ISODate(“2018-09-10T16:26:44.501Z”), “assetId” : ObjectId(“5b96b7645f2b3c0101520s60”) }, { “lsd” :…

How to get result from this array to count role in mongodb

[ { “_id”: ‘1’, “role”:’admin’, “created”:”0″, }, { “_id”: ‘2’, “role”:’vendor’, “created”:”1″, }, { “_id”: ‘3’, “role”:’cus’, “created”:”1″, }, { “_id”: ‘4’, “role”:’cus’, “created”:”1″, }, { “_id”: ‘5’, “role”:’admin1′, “created”:”1″, }, { “_id”: ‘6’, “role”:’support’, “created”:”5″, }, { “_id”: ‘7’, “role”:’support’, “created”:”5″, }, ] Would like to this type of result [ { _id: 1,…

MongoDB ShardingKey error: Document does not contain shard key for pattern

I’m trying to set up sharding for mongoDB. The Shard is created successfully but everytime I try to populate the collection with help of a json file, I get the following error: Document does not contain shard key for pattern Im declaring the shard using the following command: sh.shardCollection(“velo.Users”,{Zipcode:1}) mongoimport –host localhost –port 1000 –db…