VOMongoRepository无法使用用户凭据(Pharo / Voyage)连接到MongoDB副本集

时间:2018-08-30 12:56:00

标签: mongodb smalltalk pharo

我正在尝试将一个根对象(MyDocument)保存到启用了身份验证以及一个由3个节点组成的ReplicaSet的mongoDB中(插入mongoUrls中)

通过此电话: public class CalendarQuickstart { private static final String APPLICATION_NAME = "Apps Script"; private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance(); private static final String TOKENS_DIRECTORY_PATH = "tokens"; /** * Global instance of the scopes required by this quickstart. If modifying these * scopes, delete your previously saved tokens/ folder. */ private static final List<String> SCOPES = Collections.singletonList(CalendarScopes.CALENDAR); private static final String CREDENTIALS_FILE_PATH = "/ReservaSalaKeys.json"; /** * Creates an authorized Credential object. * * @param HTTP_TRANSPORT * The network HTTP Transport. * @return An authorized Credential object. * @throws IOException * If the credentials.json file cannot be found. */ private static Credential getCredentials(final NetHttpTransport HTTP_TRANSPORT) throws IOException { // Load client secrets. InputStream in = CalendarQuickstart.class.getResourceAsStream(CREDENTIALS_FILE_PATH); GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in)); // Build flow and trigger user authorization request. GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES) .setDataStoreFactory(new FileDataStoreFactory(new java.io.File(TOKENS_DIRECTORY_PATH))) .setAccessType("offline").build(); return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user"); } public static void main(String... args) throws IOException, GeneralSecurityException { // Build a new authorized API client service. final NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport(); Calendar service = new Calendar.Builder(HTTP_TRANSPORT, JSON_FACTORY, getCredentials(HTTP_TRANSPORT)) .setApplicationName(APPLICATION_NAME).build(); Iterator<CalendarListEntry> it = service.calendarList().list().execute().getItems().iterator(); while(it.hasNext()) { System.out.println(it.next().getSummary()); } int numberOfCalendars = service.calendarList().list().size(); service.calendars().insert( new com.google.api.services.calendar.model.Calendar().setSummary("Calendario " + numberOfCalendars + 1)) .execute(); }

我收到了VOMongoConnectionError,没有任何更详细的信息。

对此尝试相同:

(VOMongoRepository mongoUrls: {'127.0.0.1:27017' . '127.0.0.1:27018' . '127.0.0.1:27019'} database: 'myDB' username: 'myUser' password: 'myPass') enableReplication

然后我收到VOMongoError“未授权对myDB.MyDocument进行查询”

使用mongo客户端和Compass对凭据进行了双重检查,还具有读/写权限(实际上,角色是dbOwner)。

有趣的是,尽管我没有在MongoDB中创建文档,但我的testDocumentLifeCycle能够创建该对象并发送一条消息以进行保存,该消息返回时没有发出错误信号。但是selectOne:然后返回VOMongoError:

VOMongoRepository mongoUrls: {'myUser:myPass@127.0.0.1:27017/?replicaSet=myRepl' } database: 'myDB'

只需提一下:MyDocument类的上述测试确实适用于未启用身份验证的独立mongod。唯一更改的是存储库。

那我在做什么错了?

1 个答案:

答案 0 :(得分:0)

实际上,VoyageMongo的plicateSet部分中存在一个错误。它未使用提供的凭据。它已发布在https://github.com/pharo-nosql/voyage/issues/104