SyntaxError: missing ; before statement (shell):1

6,728 views
Skip to first unread message

gmail

unread,
Jul 16, 2012, 4:28:58 AM7/16/12
to mongodb-user
Hi everyone:
when I save data to the collection which name is number start , the mongo prompt "Mon Jul 16 16:16:44 SyntaxError: missing ; before statement (shell):1 ",
and my command is following:
 
PRIMARY> use testwhb
switched to db testwhb
PRIMARY> db.a.save({"test":"1"})
PRIMARY> db.1.save({"tet2":"1"})
Mon Jul 16 16:16:44 SyntaxError: missing ; before statement (shell):1
PRIMARY> show collections
 
 
Does it mongo limit the collection name start with number??

gmail

मैं एक भारतीय बेवकूफ हूँ

unread,
Jul 16, 2012, 4:32:48 AM7/16/12
to mongod...@googlegroups.com
http://www.mongodb.org/display/DOCS/Collections
> ------------------------------------------------------------------------
> gmail
>
> --
> You received this message because you are subscribed to the Google
> Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com
> To unsubscribe from this group, send email to
> mongodb-user...@googlegroups.com
> See also the IRC channel -- freenode.net#mongodb

Stephen Steneker

unread,
Jul 16, 2012, 5:14:50 AM7/16/12
to mongod...@googlegroups.com, fly542
Hi,

You can use a collection name starting with a number, but the mongo JS shell recognizes that as a beginning a variable rather than a collection name so you need to quote it:

> db["1"].save({"test2":1});

> db["1"].find();
{ "_id" : ObjectId("5003d9c1c27f710e17072683"), "test2" : 1 }

> db.getCollection("1").find()
{ "_id" : ObjectId("5003d9c1c27f710e17072683"), "test2" : 1 }

Cheers,
Stephen 

gmz

unread,
Jul 16, 2012, 5:17:10 AM7/16/12
to mongod...@googlegroups.com, fly542
Collection names should begin with letters or an underscore and may include numbers; $ is reserved. 

在 2012年7月16日星期一UTC+8下午4时28分58秒,Benk写道:

gmz

unread,
Jul 16, 2012, 5:20:07 AM7/16/12
to mongod...@googlegroups.com, fly542
And I think the error message should be more clear

在 2012年7月16日星期一UTC+8下午5时17分10秒,gmz写道:
Reply all
Reply to author
Forward
0 new messages