1

Here is my document:

{
    $set: {"paths.0.pathBreak" : {

                "1": {
                    "Key1" : [66.92, 22.34],
                    "Key2" : "Val2",
                    "Key3" : [64.92, 22.34],
                    "Key4" : "destination : dest2",
                    "transportTypes" : [{
                        "type" : "bus",
                        "fare" : {
                            "adult" : 5.0,
                            "child" : 2.0,
                            "all" : 5.0
                        },
                        "encodedPath" : "kjfghl2h34h2l4h",
                        "approxTime" : "00:00:30",
                        "info" : "direct "
                    }]  
                }
            }
        }
}

When I assign it to a variable insertDoc through mongodb shell as:

> insertDoc={
... $set: {"paths.0.pathBreak" : {
...
... "1": {
... "Key1" : [66.92, 22.34],
... "Key2" : "Val2",
... "Key3" : [64.92, 22.34],
... "Key4" : "destination : dest2",
... "transportTypes" : [{
... "type" : "bus",
...
Display all 173 possibilities? (y or n)
...         codedPath" : "kjfghl2h34h2l4h",
...               "approxTime" : "00:00:30",
...               "info" : "direct "
...             }]
... }
... }
... }
... }

Why is it not getting assigned to the variable and from where did the line

Display all 173 possibilities? (y or n)

Came from. Could someone figure it out?
Edit: I am actually pasting the document from mongoVUE into the mongo shell.

rahulserver
  • 10,411
  • 24
  • 90
  • 164
  • you need a `var` at the beginning to delcare it, though judging by the output you may also have a broken object there – Sammaye Jun 28 '13 at 11:49
  • @Sammaye I am not running it from javascript.Its from mongo shell. So var not needed.Anyways tried to declare it with var but same result. – rahulserver Jun 28 '13 at 11:51
  • The Mongo shell IS JavaScript, it is an extend JavaScript shell. But yeah, then it is definitely certain that you probably have an error in the formatting of your input there. Maybe you can show us what `insertDoc` looks like from where you are inputting it from? – Sammaye Jun 28 '13 at 11:54
  • @Sammaye "The Mongo shell IS JavaScript"-True. And I have checked all I could regarding the formatting.I could not make out the problem. – rahulserver Jun 28 '13 at 11:56
  • Can you show us the object in its raw form from where you either pasted or inputted it from? It seems like there might be a hidden character in the initial input. – Sammaye Jun 28 '13 at 11:57
  • @Sammaye I first composed the object in MongoVUE and then pasted it into the mongo shell.So d u want the mongo screenshot or the VUE screen? – rahulserver Jun 28 '13 at 12:00
  • Ok I know the problem, MongoVue will provide some new lines in the output that will break a Linux terminal, I get it all the time when I paste from odd sources; you need to write the object out again in something like notepad++ or something that can creatre standardised formatting for both Windows and Unix. Best to not include new lines at all if I am honest – Sammaye Jun 28 '13 at 12:02
  • @Sammaye Got it working! Kindly post it as the answer.Thanx!!! – rahulserver Jun 28 '13 at 12:07

1 Answers1

3

Pasting from MongoVue is causing hidden characters which are causing the mongo shell to drop out to the Linux shell during pasting.

Best option is to form it in notepad++ or another program similar and keep new lines out as well.

Sammaye
  • 43,242
  • 7
  • 104
  • 146