I am trying to insert an array of json objects into mongodb. I pass the array with a POST
request, using Spring
My object
@Document(collection = "Users")
public class User {
private String name;
private String number;
//constructors, getters, setters
}
My spring controller
@RestController
public class UserController {
@RequestMapping(value="/postUser", method = RequestMethod.POST)
public void postUser(@RequestBody BasicDBList users){
ApplicationContext ctx =
new AnnotationConfigApplicationContext(SpringMongoConfig.class);
MongoOperations mongoOperation =
(MongoOperations) ctx.getBean("mongoTemplate");
mongoOperation.insert(users);
}
}
This is my json
[
{
"name" : "a",
"number" : "1"
},
{
"name" : "c",
"number" : "3"
}
]
What I get in return is
{
"timestamp": 1499161260902,
"status": 500,
"error": "Internal Server Error",
"exception": "org.springframework.dao.InvalidDataAccessApiUsageException",
"message": "No Persistent Entity information found for the class com.mongodb.BasicDBList",
"path": "/postUser"
}
There is no problem if I do
public void postUser(@RequestBody User users)
and insert a single user. Why doesn't it work?