I'm trying to insert multiple documents to Cosmos DB with Mongo Api which has a shard key as follows,
insertAll(trips.stream().map(t -> Document.parse(gson.toJson(t))).collect(Collectors.toList()),"trip");
insertAll method is as follows,
private void insertAll(List<Document> data, String collectionName) {
MongoCollection<Document> collection = mongoTemplate.getCollection(collectionName);
collection.insertMany(data);
}
And the documents I'm trying to insert are as follows,
Document{{sensorId=b827ebe942b7, liftId=1edb945b-29e7-c6c7-d20b-87c0, timestamp=1554902007838, ..............}}
Even though I'm providing the shard key which is liftId
I get a exception saying single shard key must be provided.
Command failed with error 61: 'query in command must target a single shard key' on server cdb-ms-prod-southeastasia1-fd10.documents.azure.com:10255.
The full response is { "_t" : "OKMongoResponse", "ok" : 0, "code" : 61, "errmsg" : "query in command must target a single shard key", "$err" : "query in command must target a single shard key" }; nested exception is com.mongodb.MongoCommandException: Command failed with error 61: 'query in command must target a single shard key' on server cdb-ms-...-fd10.documents.azure.com:someport. The full response is { "_t" : "OKMongoResponse", "ok" : 0, "code" : 61, "errmsg" : "query in command must target a single shard key", "$err" : "query in command must target a single shard key" }
Any help to fix this? I'm using spring data mongodb