spring-projects / spring-projects/spring-data-rest

Posting relationship with MongoDB not possible [DATAREST-287]

Open
#667 1 comment 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 31, 2020.

in: repository type: bug
Dominant language
Java
Stars
958
Forks
568
PR merge metrics
No merged PRs in 30d

Description

Johannes Hiemer opened DATAREST-287 and commented

Today I tried to post a relationship of two entities with SD REST MongoDB. My entities are as follows:

Dicussion.java

@Document
public class Discussion extends AbstractDocument {
	
	private String title;
	
	@Indexed
	private Date created;
	
	@DBRef
	private List<Comment> comments = new ArrayList<Comment>();

Comment.java

@Document
public class Comment extends AbstractDocument {
	
	private String title;
	
	private String content;
	
	private String notes;
	
	private String color;
	
	@Indexed
	private Date created;

In Angular I am creating the Comment entity, and afterwards I am trying to POST the link relation. As I got this type of code in three areas, which are also covered by client side unit test, I am pretty sure this has worked before. The JSON payload looks like this:

POST /web/comments HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Content-Length: 82
Accept: application/json;charset=UTF-8
Origin: http://localhost:8000
{
	"title":"caaxcxcy",
	"content":"cyxcyxcxyycx",
	"created":"2014-04-09T05:26:23.468Z"
}

And the payload for the link creation:

POST /web/discussions/532d4b93a0eed7e953caec5f/comments HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Content-Length: 59
Accept: application/json;charset=UTF-8
Origin: http://localhost:8000
Content-Type: text/uri-list; charset=UTF-8
http://localhost:8080/web/comments/5344d9ffa0ee449bc6fe1413

What I get is a method not allowed. Doing it with PUT in the second step, the entity is resolved and put into Discussions. The actual problem here, is that it does not append the comment, and instead replaces the actual comment. This seems a reasonable behaviour to me, depending on the kind of perspective. The question is, why does POST suddenly fail? Is this intended, and if so, how would I solve the scenario above?

May this also be related to the other issue I openend recently where sub-entity DbRefs are ignored suddenly? So a general change in handling DbRefs of MongoDB?


Affects: 2.1 M1 (Dijkstra)

2 votes, 3 watchers

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.