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

时间:2019-09-18 18:50:25

标签: mongodb-stitch

我在从Atlas mongoDB(缝合)获取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;
    }
}

0 个答案:

没有答案