Hi everybody,
I work on a student project and discover the MongoDB world (I go back to school at 35 years old !!! :D)
After build a simple android app and finally connect my App to Realm through email/password authentification, I would like to show a part of an Atlas collection.
At the end, it will be to show just a collection’s array but for begin, and understand how it work … show a collection should be good.
But …of course … it doesn’t work and I don’t understand why.
I have a collection called “consumer” with 2 consumers inside.
consumer 1 & 2
- _Id
- email
- password
I would like to show one of the two consumers when i give the email adress.
For this, I wrote :
public HomeViewModel() {
mText = new MutableLiveData<>();User user = ClientApp.currentUser(); Functions functionsManager = ClientApp.getFunctions(user); List<String> args = Arrays.asList("florian.vigier@gmail.com"); functionsManager.callFunctionAsync("GetClient", args, String.class, result -> { if (result.isSuccess()) { Log.v("Collection Found", "La collection est trouvée : " + result.get()); UserContent = result.get(); } else { Log.e("Collection Not Found", "La collection n'est pas trouvée : " + result.getError()); } }); mText.setValue(UserContent); }
This code call the following function :
exports = function(arg){
let collection = context.services.get(“4proj”).db(“4projDB”).collection(“consumer”);
return collection.findOne({email: arg});
};
And I have the following error message :
E/Collection Not Found: La collection n’est pas trouvée : BSON_DECODING(realm::app::CustomError:1102): Error decoding value {“value”:null}
org.bson.BsonInvalidOperationException: readString can only be called when CurrentBSONType is STRING, not when CurrentBSONType is NULL.
at org.bson.AbstractBsonReader.verifyBSONType(AbstractBsonReader.java:690)
at org.bson.AbstractBsonReader.checkPreconditions(AbstractBsonReader.java:722)
at org.bson.AbstractBsonReader.readString(AbstractBsonReader.java:457)
at org.bson.codecs.StringCodec.decode(StringCodec.java:39)
at org.bson.codecs.StringCodec.decode(StringCodec.java:28)
at io.realm.internal.jni.JniBsonProtocol.decode(JniBsonProtocol.java:87)
at io.realm.mongodb.FunctionsImpl.invoke(FunctionsImpl.java:65)
at io.realm.mongodb.functions.Functions$1.run(Functions.java:146)
at io.realm.internal.mongodb.Request$1.run(Request.java:57)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:923)
I suppose that the return is not String, but I’m not really sure.
Do someone may help me to understand ?