Using mongoDB with dot "." in fields

2,523 views
Skip to first unread message

adriana_lazar

unread,
Dec 6, 2010, 10:30:56 AM12/6/10
to mongodb-user
I am having some trouble when inserting in mongo fields that contain
the . (dot) character.
I using JAVA and doing something like:

HashMap map = new HashMap();
map.put("user.password","pass");
//other params

BasicDBObject object = new BasicDBObject();
object.putAll(map);
.........

//displaying the inserted data
DBCollection col = db.getCollection(collection);
DBCursor cursor = col.find();
while (cursor.hasNext()) {
System.out.println(cursor.next());
}


Now everything seems to work fine, I see at the console all my data
including user.password

{ "_id" : { "$oid" : "4cfcefce306a5ecbe4a11566"} , "user.password" :
"pass" ,.............}


Now I want to export all this data in a csv file using mongoexport.
When I do this the user.password field is empty.
I use the command like:

mongoexport -d requests -c requests --csv -f
user.password, .......other params here..... -o d:\Work\mongo.csv

Why is this happening? I read that mongo does not accept . (dot) as
key in the field? Why do I see the correct result through Java and
using export command I get no value? I really need to log values
with . (dot).

What would be a solution for this?

Thank you!

Brendan W. McAdams

unread,
Dec 6, 2010, 10:36:03 AM12/6/10
to mongod...@googlegroups.com

The dot character should be thought of as reserved keyword in mongodb and should not be used in field names. It is typically used to query subdocuments.

> --
> 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.
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
>

adriana_lazar

unread,
Dec 6, 2010, 10:41:44 AM12/6/10
to mongodb-user
Yes, I kind-of figure that out from what I read in their site. But if
it works in Java to insert and display, that does not seem as a
"reserved word" no? :)
I am using mongo for logging purposes, and I would like not to
restrict myself of logging some of the characters. There must be some
way to indicate mongo to "escape" special characters no?

Or maybe you can somehow indicate when using mongoexport to retrieve
this 'special' field?

Thank you

On Dec 6, 5:36 pm, "Brendan W. McAdams" <bren...@10gen.com> wrote:
> The dot character should be thought of as reserved keyword in mongodb and
> should not be used in field names. It is typically used to query
> subdocuments.
> mongodb-user...@googlegroups.com<mongodb-user%2Bunsu...@googlegroups.com>
> .> For more options, visit this group at
>
> http://groups.google.com/group/mongodb-user?hl=en.
>
>

Lucas Zamboulis

unread,
Dec 6, 2010, 10:53:05 AM12/6/10
to mongod...@googlegroups.com
> Yes, I kind-of figure that out from what I read in their site. But if
> it works in Java to insert and display, that does not seem as a
> "reserved word" no? :)

http://jira.mongodb.org/browse/JAVA-151

Reply all
Reply to author
Forward
0 new messages