Search code examples
mongodbmongodb-shellmongovue

Declaration of variable unsuccessful in MongoDB shell


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.


Solution

  • 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.