Open mm765 opened 8 years ago
Oh , this doesn't happen on the find() but when i try to access the data, either using cursor.next() or cursor.toArray()
Are you creating the DB with decaf?
I really can't say what's going on for sure without seeing the code. The data type of the element doesn't seem to be compatible with JavaScript.
On Tue, Jan 5, 2016 at 6:59 PM, mm765 notifications@github.com wrote:
Oh , this doesn't happen on the find() but when i try to access the data, either using cursor.next() or cursor.toArray()
— Reply to this email directly or view it on GitHub https://github.com/decafjs/decaf/issues/13#issuecomment-169205387.
No, it is an existing database from a project (which im basically trying to re-create with decaf), my mongodb-related code has only a few lines:
eMongoDB = require('libs/decaf-mongodb').MongoDB eObjectID = require('libs/decaf-mongodb').ObjectId db = new eMongoDB('databasename') db.use('users') cu = db.users.find({}) console.log 'Count', cu.count() while(cu.hasNext()) data = cu.next() console.log 'Cursor:', data.Name
Oh and the existing project also uses javascript (node.js, which i want to get rid of, because especially database access is a nightmare, codewise )
Ok, using the debugger, it seems as if there is a problem when there is an array within an object in the document. The line from the database that creates the error (originating in Cursor.js: next() function, line ret=deserialize(ret); is: {"Languages"; ["en"], "LoginName": "b", ....} It seems as if it tries to handle the "en" as an object instead of as a string ?!
https://github.com/decafjs/decaf-mongodb/blob/master/lib/BSON.js#L47
You might step into deserialize() at that point and see where the logic is failing.
d(o) inside deserialize() right away.
On Tue, Jan 5, 2016 at 7:57 PM, mm765 notifications@github.com wrote:
Ok, using the debugger, it seems as if there is a problem when there is an array within an object in the document. The line from the database that creates the error (originating in Cursor.js: next() function, line ret=deserialize(ret); is: {"Languages"; ["en"], "LoginName": "b", ....} It seems as if it tries to handle the "en" as an object instead of as a string ?!
— Reply to this email directly or view it on GitHub https://github.com/decafjs/decaf/issues/13#issuecomment-169214361.
Callstack: BSON.js: 53 (here it throws the exception) BSON.js:75 (here, value is "en") decaf.js:41
so it tries a deserialize on en which doesn't have an entrySet() function because it is a string.
BSON.js: 74 (here, elem is Languages=["en"], key is Languages and value ["en"] decaf.js: 41 again BSON.js: 53 again
Can you paste the output of d(o) into a message here?
On Tue, Jan 5, 2016 at 8:12 PM, mm765 notifications@github.com wrote:
Callstack: BSON.js: 53 (here it throws the exception) BSON.js:75 (here, value is "en") decaf.js:41
so it tries a deserialize on en which doesn't have an entrySet() function because it is a string.
BSON.js: 74 (here, elem is Languages=["en"], key is Languages and value ["en"] decaf.js: 41 again BSON.js: 53 again
— Reply to this email directly or view it on GitHub https://github.com/decafjs/decaf/issues/13#issuecomment-169215722.
% d(o) (JavaObject) [getClass] [toCharArray] [wait] [codePointAt] [notifyAll] [replace] [regionMatches] [replaceFirst] [compareTo] [replaceAll] [getBytes] [substring] [notify] [empty] [split] [trim] [hashCode] [toUpperCase] [codePointBefore] [equalsIgnoreCase] [indexOf] [class] [compareToIgnoreCase] [codePointCount] [codePoints] [intern] [getChars] [toLowerCase] [contentEquals] [length] [isEmpty] [concat] [subSequence] [matches] [lastIndexOf] [contains] [bytes] [equals] [endsWith] [toString] [offsetByCodePoints] [chars] [charAt] [startsWith] [trimLeft] [trimRight] %
https://github.com/decafjs/decaf-mongodb/blob/master/lib/BSON.js#L47
At line 49, try adding this code:
if (!o.entrySet) { return String(o); }
On Tue, Jan 5, 2016 at 8:16 PM, mm765 notifications@github.com wrote:
% d(o) (JavaObject) [getClass] [toCharArray] [wait] [codePointAt] [notifyAll] [replace] [regionMatches] [replaceFirst] [compareTo] [replaceAll] [getBytes] [substring] [notify] [empty] [split] [trim] [hashCode] [toUpperCase] [codePointBefore] [equalsIgnoreCase] [indexOf] [class] [compareToIgnoreCase] [codePointCount] [codePoints] [intern] [getChars] [toLowerCase] [contentEquals] [length] [isEmpty] [concat] [subSequence] [matches] [lastIndexOf] [contains] [bytes] [equals] [endsWith] [toString] [offsetByCodePoints] [chars] [charAt] [startsWith] [trimLeft] [trimRight] %
— Reply to this email directly or view it on GitHub https://github.com/decafjs/decaf/issues/13#issuecomment-169216136.
yes, that works
thanks
That may not be the 100% correct solution, but it should hold you over until tomorrow when I can do the proper fix and push that code.
Maybe with this fix it won't work with array of numbers...
On Tue, Jan 5, 2016 at 8:23 PM, mm765 notifications@github.com wrote:
yes, that works
— Reply to this email directly or view it on GitHub https://github.com/decafjs/decaf/issues/13#issuecomment-169216641.
Looks like rhino since decaf uses java.lang.system.out() .. Thanks for your help, gtg.
The idea is for modules to do the translations back and forth to/from Java and JavaScript.
The code I gave you casts that Java string to a JavaScript one.
On Tuesday, January 5, 2016, mm765 notifications@github.com wrote:
Looks like rhino since decaf uses java.lang.system.out() .. Thanks for your help, gtg.
— Reply to this email directly or view it on GitHub https://github.com/decafjs/decaf/issues/13#issuecomment-169217448.
This ticket really belongs in the decaf-mongoldb repo :)
I just pushed a better version of deserialize() that should fix the issue with arrays.
Last one for today...
I tried using the mongo-driver and did a simple find({}) (find all) and got the following error: \ EXCEPTION ** TypeError: Cannot find function entrySet in object en. at /opt/itk/libs/decaf-mongodb/lib/BSON.js:53 (deserialize) at /opt/itk/libs/decaf-mongodb/lib/BSON.js:75 (anonymous) at /usr/local/decaf/builtins/decaf.js:41 (anonymous) at /opt/itk/libs/decaf-mongodb/lib/BSON.js:74 (anonymous) at /usr/local/decaf/builtins/decaf.js:41 (anonymous) at /opt/itk/libs/decaf-mongodb/lib/BSON.js:53 (deserialize) at /opt/itk/libs/decaf-mongodb/lib/Cursor.js:217 (anonymous) at server.js:21 at /usr/local/decaf/builtins/rhino.js:117 (anonymous) at /usr/local/decaf/builtins/include.js:96 (includeFile) at /usr/local/decaf/builtins/include.js:107 (anonymous) at /usr/local/decaf/builtins/shell.js:72 (anonymous) at /usr/local/decaf/builtins/shell.js:18 at /usr/local/decaf/builtins/rhino.js:117 (anonymous) at /usr/local/decaf/builtins/include.js:96 (includeFile) at /usr/local/decaf/builtins/include.js:107 (anonymous) at /usr/local/decaf/builtins/all.js:160
The "en" in the error message lets me suspect that it has a problem with an object like Name['en'] = 'Choice' Name['de'] = 'Auswahl' in the collection - using a different collection that does not have an Object like that, works. Any idea ?