[CSHARP-545] Create document copies in a collection without pulling the document out Created: 17/Aug/12  Updated: 05/Apr/19  Resolved: 27/Aug/12

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Minor - P4
Reporter: Zarian Waheed Assignee: Unassigned
Resolution: Done Votes: 0
Labels: question
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Is there a way to create a copy of an existing document without pulling out the document to the application. Currently this is what we are doing:

1) Read the existing document.
2) Apply some changes (change a field)
3) Save this document as a new document. (The original document stays the same)

Since our documents can be big, so we were wondering if we can do this:

1) Call some function with a document id and the fields we want to change.
2) On the mongo server side, the document is read, changed and a new document is created.

This way we are hoping to avoid pulling the document out of the mongo to the application. We think we can gain some performance out of it.

Is this supported? (Maybe through a javascript function).
If its possible then is this approach recommended?
Can you suggest something different that might be a better solution?



 Comments   
Comment by Craig Wilson [ 17/Aug/12 ]

First off, please use the google groups for questions like this. You can get to it here: https://groups.google.com/forum/#!forum/mongodb-user

Answer:
It's generally not advisable to use a server side javascript function for this. The current javascript interpreter on the server is single-threaded and it would definitely impact your throughput. However, there are ways of sending updates to the server without reading the document, changing it, and sending it back. You can read about the update method here: http://www.mongodb.org/display/DOCS/Updating/ and the corresponding method in the driver to execute them. http://www.mongodb.org/display/DOCS/CSharp+Driver+Tutorial#CSharpDriverTutorial-Updatemethod. Also, take notice of the findAndModify command.

Generated at Wed Feb 07 21:37:09 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.