Use of Shell to get JSON from a MongoDB

Javier Miranda V. jemirandav at gmail.com
Wed Mar 5 11:19:14 EST 2014


After strugling and finally understand with help from friends at
Stackoverflow, how the find() command works in the interative javascript
shell of MongoDB, now I know that find() returns a cursor.

 

But still have some problems trying to get JSON from my local MongoDB.

Issuing:
db.test.find() -- This works in the shell because, internally it iterates in
the cursor contents to show the documents.

It show the same documents when you:
var c = db.test.find() 
while ( c.hasNext() ) printjson( c.next()) 

The thing now is how to code this in LiveCode, I tried this in a mouseup
handler: 


put shell("C:\mongodb\bin\mongo.exe --eval var c = db.test.find() ; while (
c.hasNext() ) printjson( c.next() )") into pJSON 
put pJSON into fld "A" -- this step is only to "see"what is the result,
pJSON, once all is worj=king will be passed to a function to make it an
array.

But what i get in field "A" is:


MongoDB shell version: 2.2.7
connecting to: c
Sun Mar 02 01:12:52 SyntaxError: missing variable name (shell eval):1

Hope you can guide me!

Javier




More information about the use-livecode mailing list