我有以下内容:
one or zero to many
第二部分是打印集合中的所有文档。但是,每次重新运行程序时,集合都不会清除。有谁知道为什么?
答案 0 :(得分:0)
而不是这样做
@Controller
public class LoginController {
@RequestMapping(value = "/login", method = RequestMethod.GET)
public ModelAndView showLogin(HttpServletRequest request, HttpServletResponse response) {
ModelAndView mav = new ModelAndView("login");
mav.addObject("login", new LoginBean());
return mav;
}
@RequestMapping(value = "/loginProcess", method = RequestMethod.POST)
public ModelAndView loginProcess(HttpServletRequest request, HttpServletResponse response,
@ModelAttribute("login") LoginBean login) {
ModelAndView mav = null;
try {
/*
* Will add the logic for validate User later
*/
//User user = userService.validateUser(login);
if (null != login) {
mav = new ModelAndView("welcome");
mav.addObject("<i>Happy to see you </i>",login.getXid());
} else {
mav = new ModelAndView("login");
mav.addObject("message", "Please check.. Xid or Password may be wrong !!!");
}
}
catch(Exception ex){
ex.printStackTrace();
}
return mav;
}
这样做
db.collection.remove({})
此外,您还不需要此行db.accounts.remove({})
如果需要动态集合名称,可以执行以下操作:
collection=db['accounts']
答案 1 :(得分:0)
而不是
db.collection.remove({})
你可以试试这个
collection.delete_many({})
希望能解决你的问题。
答案 2 :(得分:0)
只需这样做
db.accounts.drop()