Copy specific columns to collection

116 views
Skip to first unread message

megha garg

unread,
Oct 9, 2014, 3:05:45 AM10/9/14
to mongod...@googlegroups.com
Is there a way to copy specific columns of one collection to another collection?

Will Berkeley

unread,
Oct 9, 2014, 11:42:48 AM10/9/14
to mongod...@googlegroups.com
There's no concept of a "column" in MongoDB. Can you explain what you mean? Including sample source and target documents is most helpful.

-Will

Alex Frieden

unread,
Oct 9, 2014, 11:44:51 AM10/9/14
to mongod...@googlegroups.com
I think they want to project certain fields or properties of a document from one collection to another

On Thu, Oct 9, 2014 at 11:42 AM, Will Berkeley <william....@mongodb.com> wrote:
There's no concept of a "column" in MongoDB. Can you explain what you mean? Including sample source and target documents is most helpful.

-Will

--
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/e7680a8a-2af4-4bfa-bb86-245b647e0261%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Alexander Frieden

Will Berkeley

unread,
Oct 9, 2014, 12:01:42 PM10/9/14
to mongod...@googlegroups.com
Indeed - but still need more details. Which fields? Without modification? How do you tell which document(s) to send a field to? etc.

-Will

megha garg

unread,
Oct 10, 2014, 2:07:38 AM10/10/14
to mongod...@googlegroups.com
Sorry for missing out the details in my previous email.

Below is my source collection:-

db.employee.find()
{ "_id" : ObjectId("5437725f3fcc6c33f2b08e4e"), "eid" : 1, "name" : "emp1", "gender" : "f" }
{ "_id" : ObjectId("543772a73fcc6c33f2b08e4f"), "eid" : 2, "name" : "emp2", "gender" : "m", "Spouse" : "Y" }
{ "_id" : ObjectId("543772b83fcc6c33f2b08e50"), "eid" : 3, "name" : "emp3", "gender" : "m", "Spouse" : "Y", "Children" : 2 }
{ "_id" : ObjectId("543772d43fcc6c33f2b08e51"), "eid" : 4, "name" : "emp4", "gender" : "m", "Spouse" : "Y" }
{ "_id" : ObjectId("543772dd3fcc6c33f2b08e52"), "eid" : 5, "name" : "emp5", "gender" : "m" }
{ "_id" : ObjectId("5437733c3fcc6c33f2b08e53"), "eid" : 6, "name" : "emp6", "gender" : "f", "Spouse" : "N" }
{ "_id" : ObjectId("543773493fcc6c33f2b08e54"), "eid" : 7, "name" : "emp7", "gender" : "f", "Spouse" : "Y", "Children" : 3 }


I meant to copy all the documents of employee collection but only _id,eid,name and gender fields in a new collection named "data". How can I do it?
Reply all
Reply to author
Forward
0 new messages