Clone a collection in MongoDB
Yet again the MongoDB documentation comes to the rescue assuming that the collection actually is named “demo1.categories”: db.demo1.categories.find().forEach( function(x){db.demo2.categories.insert(x)} );
Yet again the MongoDB documentation comes to the rescue assuming that the collection actually is named “demo1.categories”: db.demo1.categories.find().forEach( function(x){db.demo2.categories.insert(x)} );
The best way is to do a mongodump then mongorestore. You can select the collection via: mongodump -d some_database -c some_collection [Optionally, zip the dump (zip some_database.zip some_database/* -r) and scp it elsewhere] Then restore it: mongorestore -d some_other_db -c some_or_other_collection dump/some_collection.bson Existing data in some_or_other_collection will be preserved. That way you can “append” a … Read more
From the MongoDB docs: A projection can explicitly include several fields. In the following operation, find() method returns all documents that match the query. In the result set, only the item and qty fields and, by default, the _id field return in the matching documents. db.inventory.find( { type: ‘food’ }, { item: 1, qty: 1 … Read more
Use aggregation db.UserData.aggregate({$group:{_id:”$category”, “maxValue”:{$max:”$value”}}});