我正在尝试使用具有分片键的Mongo Api将多个文档插入Cosmos DB,
insertAll(trips.stream().map(t -> Document.parse(gson.toJson(t))).collect(Collectors.toList()),"trip");
insertAll方法如下,
private void insertAll(List<Document> data, String collectionName) {
MongoCollection<Document> collection = mongoTemplate.getCollection(collectionName);
collection.insertMany(data);
}
我要插入的文档如下,
Document{{sensorId=b827ebe942b7, liftId=1edb945b-29e7-c6c7-d20b-87c0, timestamp=1554902007838, .......}}
即使我提供了liftId
的分片键,但我还是遇到了一个例外,说必须提供单个分片键。
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" }
有任何解决方法吗?我正在使用spring data mongodb