Closed dandv closed 10 years ago
Hey Dan,
Sure, but you would be better off doing this the much more performant way:
db.content.insert(db.articles.find().toArray());
It should be apparent from the output that you are doing an insert for every item (and round trip to the database) instead of a single bulk insert.
There is also mongodump/mongorestore which should be used for large collections.
Does that make sense? There is a way to disable it by turning off the verbose messages but I'm not sure you want to.
Hi Tyler, the toArray()
is indeed faster, but I need to alter the record before inserting it in the other collection (item.type = 'article'
). I could run var a = db.articles.find().toArray()
then modify a
, then db.content.insert(a)
.
Sure:
var articles = db.articles.find().toArray();
articles.forEach(function(item){ item.type = 'article' });
db.content.insert(articles);
It would be much faster to use the database instead of javascript for this (if you have millions of documents, or something like that):
// copy the data using mongodump/restore or bulk insert, then:
db.content.update(
{ /* all the things */ },
{ "$set": { type: "article" } },
{ multi: true }
)
Closing this out, if you have any other questions, let me know.
New to mongo_hacker... is there a way to disable the repeated displays of
Inserted 1 record(s) in 0ms
for queries like