Views not working on CBL/ForestDB on Android

Some background, I’m evaluating CBL for a new mobile app and ran into some trouble with ForestDB. First of all, I should say that encryption is a must for us so ForestDB was our first look. We’re also using React-Native (so the REST API). I’ve modified react-native-couchbase-lite bindings to allow me to create an encrypted ForestDB (here: https://github.com/twistle/react-native-couchbase-lite). Disregarding encryption for the moment (since it’s not implemented in the REST API yet).

I added some basic data with _bulkDocs and verified that the data exists in the database. I did the same for a design document. When I queried the view, I got no results. The exact same code produced results when I switched off the ForestDB flag. There are several layers of projects on Github so I’m not sure which is the right one to file a bug under. Can someone guide me?

Thanks

1 Like

Hi, I am using react-native couchbase-lite too(by using this Component),and I am using forestdb as storageType(by changing the code of startCBLite() metohd). My view works fine.

Awesome! I was hoping for something that exposed the Java API rather than the REST API. Thanks. I’ll look at this.

The code to using forestdb haven’t push to github.I just hard code to using forestdb as storeType.

What’s better about this approach is that I can use encryption as well (since it uses the native API). I know how to add it, I’ll probably fork the Upinion version though since it has iOS as well.

ok, I can share my code If you need.

It’s always nice to see other code. Maybe I’ll learn something.


FYI

Do you have sample code for Database Encryption on forestDB (android)?

found it.

Example code here: https://github.com/fraserxu/react-native-couchbase-lite/compare/master...twistle:master#diff-9dfeffb3a18c69ace4ba5f82da6cac58R40

Thank you.I will try.

I’m getting this error. I think this was my original problem.

I/Database( 8842): Invalid filename as a view store: filename=db.forest.0 I/Database( 8842): Invalid filename as a view store: filename=db.forest.meta I/Database( 8842): Invalid filename as a view store: filename=attachments V/View ( 8842): twistle/conversations has no map block; skipping it E/View ( 8842): Error in obj -> json E/View ( 8842): com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class org.mozilla.javascript.Undefined and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) ) E/View ( 8842): at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.failForEmpty(UnknownSerializer.java:59) E/View ( 8842): at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.serialize(UnknownSerializer.java:26) E/View ( 8842): at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:129) E/View ( 8842): at com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:3383) E/View ( 8842): at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsBytes(ObjectMapper.java:2801) E/View ( 8842): at com.couchbase.lite.store.ForestDBViewStore$1.emit(ForestDBViewStore.java:319) E/View ( 8842): at com.couchbase.lite.javascript.scopes.MapGlobalScope.emit(MapGlobalScope.java:39) E/View ( 8842): at java.lang.reflect.Method.invoke(Native Method) E/View ( 8842): at java.lang.reflect.Method.invoke(Method.java:372) E/View ( 8842): at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:161) E/View ( 8842): at org.mozilla.javascript.FunctionObject.call(FunctionObject.java:476) E/View ( 8842): at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1701) E/View ( 8842): at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:854) E/View ( 8842): at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:164) E/View ( 8842): at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:426) E/View ( 8842): at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3178) E/View ( 8842): at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:162) E/View ( 8842): at com.couchbase.lite.javascript.ViewMapBlockRhino.map(ViewMapBlockRhino.java:66) E/View ( 8842): at com.couchbase.lite.store.ForestDBViewStore.emit(ForestDBViewStore.java:315) E/View ( 8842): at com.couchbase.lite.store.ForestDBViewStore.updateIndexes(ForestDBViewStore.java:276) E/View ( 8842): at com.couchbase.lite.View.updateIndexes(View.java:321) E/View ( 8842): at com.couchbase.lite.View.updateIndex(View.java:294) E/View ( 8842): at com.couchbase.lite.router.Router.queryDesignDoc(Router.java:2088) E/View ( 8842): at com.couchbase.lite.router.Router.do_GET_DesignDocument(Router.java:2119) E/View ( 8842): at java.lang.reflect.Method.invoke(Native Method) E/View ( 8842): at java.lang.reflect.Method.invoke(Method.java:372) E/View ( 8842): at com.couchbase.lite.router.Router.start(Router.java:489) E/View ( 8842): at com.couchbase.lite.listener.LiteServlet.service(LiteServlet.java:128) E/View ( 8842): at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) E/View ( 8842): at Acme.Serve.Serve$ServeConnection.runServlet(Serve.java:2251) E/View ( 8842): at Acme.Serve.Serve$ServeConnection.parseRequest(Serve.java:2176) E/View ( 8842): at Acme.Serve.Serve$ServeConnection.run(Serve.java:1988) E/View ( 8842): at Acme.Utils$ThreadPool$PooledThread.run(Utils.java:1223) E/View ( 8842): at java.lang.Thread.run(Thread.java:818)

This is the problem:

JsonMappingException: No serializer found for class org.mozilla.javascript.Undefined

Sounds like you emitted a JavaScript Undefined object as a key or value, or as part of one, and the Jackson library can’t serialize that to JSON (since Undefined is not the same as null.)

Since you don’t get this with a SQLite database, I’m guessing that the Java implementation’s SQLite storage code has a workaround for this, probably converting the Undefined to a null, but the ForestDB storage code doesn’t have the same workaround. (@hideki would know for sure.)

The workaround would be to avoid letting Undefined values be passed to emit() and use null instead.

It seems javascript’s undefined is mapped to[ Undfined class] (https://github.com/mozilla/rhino/blob/master/src/org/mozilla/javascript/Undefined.java#L17). Then this class is not serializable by Jackson. JavaScript map function should not emit undefined as @jens wrote in previous comment. Or couchbase-lite-java-javascript should ignore emit with undefined or automatically convert to null.