how to write mongo shell when i create a new collection from 1 existing collection

71 views
Skip to first unread message

amazo...@gmail.com

unread,
Jul 1, 2015, 3:16:48 AM7/1/15
to mongod...@googlegroups.com
how to write mongo shell when i create a new collection from 1 existing collection.sth like below sql
create table xxx as select * from xxx;

amazo...@gmail.com

unread,
Jul 1, 2015, 4:40:15 AM7/1/15
to mongod...@googlegroups.com
I tried below for copy system.profile to tmp collection,but it's throw below error,what's the problem?

PRIMARY> db.system.profile.find().forEach( function(x){db.tmp.insert(x)} );
2015-07-01T16:35:01.124+0800 E QUERY    Error: field names cannot start with $ [$gt]
    at Error (<anonymous>)
    at DBCollection._validateForStorage (src/mongo/shell/collection.js:161:19)
    at DBCollection._validateForStorage (src/mongo/shell/collection.js:165:18)
    at DBCollection._validateForStorage (src/mongo/shell/collection.js:165:18)
    at insert (src/mongo/shell/bulk_api.js:646:20)
    at DBCollection.insert (src/mongo/shell/collection.js:243:18)
    at (shell):1:54
    at DBQuery.forEach (src/mongo/shell/query.js:414:9)
    at (shell):1:26 at src/mongo/shell/collection.js:161


amazo...@gmail.com於 2015年7月1日星期三 UTC+8下午3時16分48秒寫道:

Stephen Steneker

unread,
Jul 2, 2015, 11:02:42 AM7/2/15
to mongod...@googlegroups.com, amazo...@gmail.com
On Wednesday, 1 July 2015 18:40:15 UTC+10, amazon.xia wrote:
I tried below for copy system.profile to tmp collection,but it's throw below error,what's the problem?
IMARY> db.system.profile.find().forEach( function(x){db.tmp.insert(x)} );

2015-07-01T16:35:01.124+0800 E QUERY    Error: field names cannot start with $ [$gt]

Hi,

The issue is that system profiling creates documents with field names using reserved characters (eg. a leading "$" for operators). These do not pass the normal validation criteria: https://jira.mongodb.org/browse/SERVER-6768.

What is your goal in copying the profile data to another collection?

If you want to re-insert the profiling data into another collection you could translate reserved characters to allowable (and perhaps visually equivalent) ones:

The profiling data is only intended as a diagnostic aid. If you want to collect more data you could:

 - Increase the slow operation threshold or logging level and capture relevant details from the mongod.log files (mtools is very handy for log file analysis: https://github.com/rueckstiess/mtools).

Regards,
Stephen

amazo...@gmail.com

unread,
Jul 3, 2015, 2:03:52 AM7/3/15
to mongod...@googlegroups.com
Hi Stephen,

my purpose copy docu from system.profile due to when i want to mapreduce on system.profile to get number of slow query group by "ns",then suddently all secondary down,so i had to copy document from system.profile to another temp collection to do the aggre.

amazo...@gmail.com於 2015年7月1日星期三 UTC+8下午3時16分48秒寫道:

Asya Kamsky

unread,
Jul 4, 2015, 6:14:22 AM7/4/15
to mongodb-user

Why not use aggregation framework to query profile collection?

--
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/135e3d62-ea80-494b-b2d6-fea78ed6089f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages