Field retrieved from a Mongo document display wrong characters

Javier Miranda jemirandav at gmail.com
Fri Sep 19 17:42:20 EDT 2014


I have a local Mongo Server and a LiveCode Stack to work as front end to
it.   When I enter "Se cambiarán los bornes" (please note the accent), in a
LiveCode field, the text is properly shown, inserting it as a document to a
Mongo collection also works fine, the field is saved OK in the document. I
can see it using the Shell. The problem is that, when I retrieve the
document back to LiveCode, the field receiving the field shows: "Se
cambiarían los bornes". Trying to find the reason I found that the
encoding of field "resul" , the field receiving the accented string is
Native. Can you help finding the way to make this strings show the right
characters?

The code in the button retrieving the document from mongo is:

on mouseUp

local theMongo, theDB, dbText, theCole, thePreg, theQuerry

put empty into field resul

put "C:\mongodb\bin\mongo.exe localhost:27017/" into theMongo

put "BatGar" into theDB

put "BatRegis"into theCole

put "'" & field F1 & "'" into toFind

put "{"& quote & "_id" & quote & ":" &  toFind & "}" into thePreg

put "; printjson(db.getLastError())" into dbErr

put  ".find(" & thePreg & ");"into theQuerry

put "var c=db."& theCole & theQuerry into dbText

put " while(c.hasNext())" after dbText

put " printjson(c.next())" after dbText

put dbErr after dbText

put theMongo & theDB &&  "--eval"  && quote & dbText & quote  into dbText1

put shell ( quote &dbText1 & quote) into dbResultado

put the number of lines of dbResultado into nro

put line 3 to (nro - 1) of dbResultado into field resul

if field resul is  empty   then

    Answer warning "El Documento NO ha sido encontrado.  El sistema no
tiene registrada una Batería con el ID: " &  field F1  with OK

else

    Answer warning "El Documento ha sido encontrado, ID: " &  field F1
with OK

end if
end mouseUp


Saludos,
Javier



More information about the use-livecode mailing list