After I successfully implemented the retrieval of documents from my local mongo server, I began trying the opposite, sending data stored in a data grid (DG) to the server, so I created a card with:
- a DG (DG_02) with two columns, _id and Nombre, a field (E),
- a script with a mouseup handler,
that:
put the dgData of DG_02 into pArray2
puts the 5th element of pArray2,into pArray,
(I just want to try this with only one element for now)
sets pForceRootType,pPretty parameters for the MergJSON function
call the function ArrayToJSON
put tJSON in fiel "E" to see what the function is returning
Construct the string for use with the shell command
put the result in rmongo to see the server answer
The whole script
on mouseUp
local dbText
put the dgData of grp "DG_02" into pArray2
put pArray2[5] into pArray <-- Only the 5th element of the array
put "string" into tipo
put "false" into bonito
put ArrayToJSON(pArray, tipo, bonito) into tJSON
put tJSON into fld "E"
put "db.nueva.insert("& tJSON & ");" into dbText
put shell("C:\mongodb\bin\mongo.exe --eval" && "'" & dbText & "'" ) into rmongo
put rmongo
end mouseUp
These are my observations when executing the script, modifying the parameter pForceRootType for the function:
When tipo is set to Object field "E" gets: {"Nombre":"Sofia","_id":1012}
When tipo is set to String, field "E" gets: {"Nombre":"Sofia","_id":"001012"}
In both cases (tipo = string or tipo = object) rmongo, show this in the message:
MongoDB shell version: 2.2.7
connecting to: test
db.nueva.insert({Nombre:Sofia,_id:001012});
The document is not inserted.
When trying the insert directly in the shell, I can see that in order to do a successful insert, the string values should be quoted, but (if I am not wrong in my observations) the JSON returned by the function does not quote the strings.
I will appreciate your guide with this, thank you in advance, Javier