2

I'm continuing practicing with LiveCode and MongoDB. I made a stack with a button with a script connecting to my local MongoDB instance. This script "builds" a query. When my code produces this:

C:\mongodb\bin\mongo.exe localhost:27017/BatGar --eval "var c=db.BatRegis.find(); while(c.hasNext()) printjson(c.next())"

I get documents from the server.

But when my code produces:

C:\mongodb\bin\mongo.exe localhost:27017/BatGar --eval "var c=db.BatRegis.find({"inspec":"No"}); while(c.hasNext()) printjson(c.next())"

or

C:\mongodb\bin\mongo.exe localhost:27017/BatGar --eval "var c=db.BatRegis.find({inspec:"No"}); while(c.hasNext()) printjson(c.next())"

I get error:

MongoDB shell version: 2.2.7
connecting to: localhost:27017/BatGar
Thu Apr 03 20:35:30 ReferenceError: No is not defined (shell eval):1

Any ideas?

hrbrmstr
  • 77,368
  • 11
  • 139
  • 205
Javier
  • 75
  • 5
  • Quoting. Your "" are cutting off at the start of "No". – Neil Lunn Apr 04 '14 at 01:48
  • Replacing the double quotes with single quotes solved the problem, now it's a matter of expanding the script to make everything variable by populating the querry with values entered in fields. – Javier Apr 04 '14 at 21:37

1 Answers1

1

Use curly quotes or single quotes:

C:\mongodb\bin\mongo.exe localhost:27017/BatGar --eval "var c=db.BatRegis.find({inspec:`No`}); while(c.hasNext()) printjson(c.next())"

or

C:\mongodb\bin\mongo.exe localhost:27017/BatGar --eval "var c=db.BatRegis.find({inspec'No'}); while(c.hasNext()) printjson(c.next())"
Mark
  • 2,380
  • 11
  • 29
  • 49