document doesn't break lines on new line characters in mongo shell

2,677 views
Skip to first unread message

Ankit Chandra

unread,
Oct 30, 2012, 1:33:44 AM10/30/12
to mongodb-user
Hi!

I am trying to load an entire log file into a document in mongodb. I
first break the log file into lines, do some processing on the
individual lines and then concatenate them together to insert them
into mongodb. Now the issue is that no matter what I try,
db.collection.find(), or db.collection.find().pretty() commands don't
display the inserted documents broken up into separate lines, on the
basis of the "\n"s I added in between the lines.

What am I missing? How can I add new line characters to the document
such that i can have them on a new line as needed? it currently shows
up as:

> db.r_20120322110650_20040911.find().pretty();
{
"_id" : ObjectId("507f94161a86693a1a000000"),

"generic" : "\n -- beginning my random stuff \n -- ExecProg: Running
fullcommand = /usr/bin/time --verbose -o what-on-earth.txt \n this is
crazy/ ........
...
...
...
}

Notice the "\n"s strewn all about the document...

Any way I can have it show up as:

> db.r_20120322110650_20040911.find().pretty();
{
"_id" : ObjectId("507f94161a86693a1a000000"),

"generic" : "
-- beginning my random stuff
-- ExecProg: Running fullcommand = /usr/bin/time --verbose -o what-on-
earth.txt
this is crazy/ ........
...
...
...
}


Thanks!

Kay

unread,
Oct 30, 2012, 1:53:28 PM10/30/12
to mongod...@googlegroups.com
Hi Ankit -- 
I believe you just want:

obj = db.r_20120322110650_20040911.find().forEach( function (myrecord) { print ("_id: " + myrecord._id); print ("generic:" + myrecord.generic); } )

This will print out:

_id: 5090139bd96f9f6c99b00b1b
generic:
 -- beginning my random stuff 
 -- ExecProg: Running fullcommand = /usr/bin/time --verbose -o what-on-earth.txt 
  this is  crazy/ ... 

Hope this helps.

Regards,

Kay

Ankit Chandra

unread,
Oct 30, 2012, 10:18:21 PM10/30/12
to mongodb-user
That works like a charm! Thanks Kay :)
Reply all
Reply to author
Forward
0 new messages