2

我在从 atlas mongoDB (stitch) 获取 android 中的数据时遇到问题:

找不到服务:'mongodb-atlas'

StitchError:找不到服务:'mongodb-atlas'

{
  "arguments": [
    {
      "database": "vutuduDB",
      "collection": "test",
      "query": {},
      "limit": {
        "$numberInt": "0"
      },
      "project": null,
      "sort": null
    }
  ],
  "name": "find",
  "service": "mongodb-atlas"
}

此外,当我尝试创建 http 服务并使用控制台时,我在运行该行时遇到了同样的问题:

context.services.get("mongodb-atlas");

Java代码:

public class SearchFragment extends Fragment {
    Button btnSearch;

    private StitchAppClient stitchClient;
    private RemoteMongoClient mongoClient;
    private RemoteMongoCollection itemsCollection;

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, 
        @Nullable Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);

        View layout = inflater.inflate(R.layout.search_fragment_layout, container, false);

        this.stitchClient = Stitch.getDefaultAppClient();

        Log.d("stitch", "logging in anonymously");
        stitchClient.getAuth().loginWithCredential(new AnonymousCredential()
        ).continueWithTask(new Continuation<StitchUser, Task<Void>>() {
            @Override
            public Task<Void> then(@NonNull Task<StitchUser> task) throws Exception {
                if (task.isSuccessful()) {
                    Log.d("stitch", "logged in anonymously as user " + task.getResult());
                } else {
                    Log.e("stitch", "failed to log in anonymously", task.getException());
                }

                mongoClient = stitchClient.getServiceClient(RemoteMongoClient.factory, "mongodb-atlas");
                RemoteMongoDatabase db = mongoClient.getDatabase("vutuduDB");

                Log.d("stitch", "GETTING ITEMS");

                db.getCollection("test").find().forEach(item -> Log.d("ITEM: ", item.toString()));

                return null;
            }
        });

        return layout;
    }
}
4

0 回答 0