Restheart add an new document in an shard collection

114 views Asked by At

I want to add an new document in an mongodb existant collection. But this collection is a shard collection. My shard key is _id.

POST http://ip:8080/db/coll

{"CODE_LOG":260,"Date": {"$date" : "2015-10-27T18:21:37.55Z" }}

I get this error :

{"http status code":400,"http status description":"Bad Request","message":"Write request for sharded collection must specify the shardkey. Use the 'shardkey' query parameter."}

I don't want to specify the value of the shardkey.

1

There are 1 answers

0
Andrea Di Cesare On

The error (code 61) is from MongoDB. RESTHeart just manages it and returns the error message that you reported with response status code 400 BAD REQUEST.

See error codes here

error_code("ShardKeyNotFound", 61)

However the restheart documentation page about shardkey reports

When a shared collection has shard key different than _id or a compound shard key, the shardkey query parameter must be used.

You should check your configuration and make sure that the shard key is actually only the _id.