您好,我是mongodb的新用户,我真的不明白我如何无法删除和使用findOneAndDelete尝试过的其他对象内的对象,但是它也删除了我在Google中搜索的所有json,我看到了$ sunset,但实际上我不知道如何在Java中使用,这里是我的代码:
@Override
public boolean eliminarContacto(String nombreContacto,String username) throws RemoteException {
try {
collection = db.getCollection("usuarios");
BasicDBObject whereQuery = new BasicDBObject();
whereQuery.put("nombre", username);
collection.find(whereQuery);
BasicDBObject deleteQuery = new BasicDBObject();
deleteQuery.put("nombre", nombreContacto);
collection.findOneAndDelete(deleteQuery);
//MongoCollection<Document> collection = db.getCollection("contacto");
//collection.deleteOne(query);
return true;
} catch (Exception e) {
System.out.println(e.getMessage());
return false;
}
}
这是我的json:
[ { “ id”:“ 1”, “ nombre”:“ pablo”, “ contacto”:[ { “ nombre”:“耶稣”, “ direccion”:“ alameda”, “ telefono”:“ 53633536” } ] }, { “ id”:“ 2”, “ nombre”:“大卫”, “ contacto”:[ { “ nombre”:“ carlos”, “ direccion”:“ bronce”, “ telefono”:“ 65645464” } ] } ]
我不想从当前用户中删除耶稣。 谢谢