db.todos.insert({title: "write a blog post'}) returns syntax error

114 views
Skip to first unread message

shareyourpeace

unread,
Feb 1, 2015, 5:26:01 PM2/1/15
to mongod...@googlegroups.com
I just cannot get started.
terminal command line

    db.todos.insert({title: "write a blog post"})

returns 

    -bash: syntax error near unexpected token `{title:'

Using this tutorial:


on a Macbookpro.


Jorge Rúa

unread,
Feb 1, 2015, 7:09:46 PM2/1/15
to mongod...@googlegroups.com
That´s b/c you are issuing the command in the wrong interpeter. That´s bash, not the mongo shell.



--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/56cfe964-1c67-463f-9d3b-30e6ddad9b98%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

s.molinari

unread,
Feb 2, 2015, 9:21:18 AM2/2/15
to mongod...@googlegroups.com
Yes, you need to type "mongo" first to get the mongo shell running. Then you can start inputting db commands.

Scott

regg

unread,
Feb 2, 2015, 6:20:28 PM2/2/15
to mongod...@googlegroups.com
Ah.  So I need to navigate into the mongo directory and issue the command.

Thanks for the reminder :)
Will update.

Really thanks.
I was stuck :)
You received this message because you are subscribed to a topic in the Google Groups "mongodb-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mongodb-user/7vY6bqtI_uc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mongodb-user...@googlegroups.com.

To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.

For more options, visit https://groups.google.com/d/optout.


--
balance  harmony  green  coexist

s.molinari

unread,
Feb 2, 2015, 11:46:05 PM2/2/15
to mongod...@googlegroups.com
You shouldn't even need to navigate to the mongo directory. Just type in "mongo" and you should be in the shell.

Scott

Stephen Steneker

unread,
Feb 3, 2015, 12:35:31 AM2/3/15
to mongod...@googlegroups.com
On Tuesday, 3 February 2015 15:46:05 UTC+11, s.molinari wrote:
You shouldn't even need to navigate to the mongo directory. Just type in "mongo" and you should be in the shell.

You will need to navigate to the "bin" directory where the `mongo` executable lives if this isn't in your default shell path.

I noticed the tutorial originally referenced in this thread describes installing MongoDB with a manual approach and doesn't include steps to update your shell path (or add a LaunchAgent service so mongod can run automatically on startup).

For simpler install/updates on OS X I would suggest installing via the Homebrew package manager as per the MongoDB manual:

The Homebrew package recipe creates default directories, updates your path, and sets mongod to run on startup (similar to the recommended packaged installs for Linux distributions).

Regards,
Stephen

Tim Hawkins

unread,
Feb 3, 2015, 2:40:32 AM2/3/15
to mongod...@googlegroups.com
The article he is working from has a critical spelling error in it 

"you have to run the mogo executable in the"

On Tue, Feb 3, 2015 at 12:46 PM, s.molinari <scottam...@googlemail.com> wrote:
You shouldn't even need to navigate to the mongo directory. Just type in "mongo" and you should be in the shell.

Scott

--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.

regg

unread,
Feb 3, 2015, 9:27:03 AM2/3/15
to mongod...@googlegroups.com
​Thank all of you. (Tim - I did know that was a typo :) but thanks.  I will email the author for the sake of others.

I posted simultaneously to a couple of forums.  
Now I have copied my mongodb-osx-x86_64.... archive folder from my desktop into my 
usr/local/bin folder.

I navigate to that bin folder and start the mongo shell but I have to use 
./mongod
not 
mongo or mongod

If you have a chance to cross reference, I posted all of my file commands and files structure and a few more questions on this post.  I like to 'understand' what I am doing and how things work.

Regarding your clarifications and suggestions - yes they are helping me to understand.

Stephen, I considered doing the install with Homebrew package manager but I have a concern.
I do not want multiple copies of these files around causing confusion for me and conflict for my mac :)

How does the install/updates on OSX work ?  
​Can I only do this for my Mongo Files ? 
I have not used Homebrew before.





--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to a topic in the Google Groups "mongodb-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mongodb-user/7vY6bqtI_uc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.

For more options, visit https://groups.google.com/d/optout.

regg

unread,
Feb 3, 2015, 9:41:34 AM2/3/15
to mongod...@googlegroups.com
thanks Scott.  I know you guys like things 'short' but I have to show the commands and output so you understand where I am coming from.
Can you read the other response that I just sent too.
Check out the below.  Follow how I inadvertently tested this.
I just did what you said and typed 'mongo';  there is the prompt > to type commands.

macbookpro:~ regina$ mongo
MongoDB shell version: 2.6.7
connecting to: test
Server has startup warnings: 
2015-02-03T08:37:08.713-0500 [initandlisten] 
2015-02-03T08:37:08.713-0500 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
 
But I realized that I had the mongo shell running already.  I had another bash window open as I was updating forum question.  See the below.

macbookpro:~ regina$ cd /usr/local/bin
macbookpro:bin regina$ ls
bower coffee gulp mkdirp mongoexport mongoperf mongostat npm
browserify cordova http-server mongo mongofiles mongorestore mongotop statsd
bsondump express karma mongod mongoimport mongos node yo
cake grunt lessc mongodump mongooplog mongosniff nodemon

macbookpro:bin regina$ ./mongod
./mongod --help for help and startup options
2015-02-03T09:32:17.979-0500 [initandlisten] MongoDB starting : pid=548 port=27017 dbpath=/data/db 64-bit host=macbookpro.home
more lines of code
2015-02-03T09:32:18.029-0500 [initandlisten] waiting for connections on port 27017

So I ^C out of the mongo shell and just typed 'mongo' as you suggested.

macbookpro:bin regina$ mongo
MongoDB shell version: 2.6.7
connecting to: test
2015-02-03T09:34:21.307-0500 warning: Failed to connect to 127.0.0.1:27017, reason: errno:61 Connection refused
2015-02-03T09:34:21.307-0500 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
exception: connect failed

and tried this.

macbookpro:bin regina$ cd ~
macbookpro:~ regina$ mongo
MongoDB shell version: 2.6.7
connecting to: test
2015-02-03T09:34:36.883-0500 warning: Failed to connect to 127.0.0.1:27017, reason: errno:61 Connection refused
2015-02-03T09:34:36.884-0500 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
exception: connect failed
macbookpro:~ regina$ 

I know that I can modify a Script Somewhere so that this command is recognized.  Homebrew, as suggested - will auto-create or modify the scripts and I am waiting for feedback because I do not want to have conflicts since I already have mongo in specific folders.

but I would not mind doing it manually if this means adding a line of code into some config file.  Either way.... I am still not crystal clear on this stuff so further hints are appreciated.
thanks to everyone.


On Mon, Feb 2, 2015 at 11:46 PM, s.molinari <scottam...@googlemail.com> wrote:
You shouldn't even need to navigate to the mongo directory. Just type in "mongo" and you should be in the shell.

Scott

--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to a topic in the Google Groups "mongodb-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mongodb-user/7vY6bqtI_uc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.

For more options, visit https://groups.google.com/d/optout.

s.molinari

unread,
Feb 3, 2015, 10:19:46 AM2/3/15
to mongod...@googlegroups.com
You need to start mongod, so the Mongo server is running. Then you type mongo to get into the shell and connect to the server (which is what failed and the error you got).

Scott 

Tim Hawkins

unread,
Feb 3, 2015, 11:19:10 AM2/3/15
to mongod...@googlegroups.com

You problem is hitting ^c after starting mongod, you have to open a new command window and type "mongo". if you hit ^c on the mongod process, you are stopping the server again, you have to leave it running.

You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.

To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.

regg

unread,
Feb 3, 2015, 11:23:09 AM2/3/15
to mongod...@googlegroups.com
Hi Tim,
Yes. I get that.  I start the server and then I open another terminal window to run the mongodb commands.
Right ?


For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages