[DOCS-7733] Comment on: "manual/reference/method/ObjectId.txt" Created: 23/Apr/16 Updated: 03/Nov/17 Resolved: 18/May/16 |
|
| Status: | Closed |
| Project: | Documentation |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | 01112017-cleanup |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Docs Collector User (Inactive) | Assignee: | Ravind Kumar (Inactive) |
| Resolution: | Done | Votes: | 0 |
| Labels: | collector-298ba4e7 | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Location: https://docs.mongodb.org/manual/reference/method/ObjectId/ |
||
| Participants: | |
| Days since reply: | 7 years, 39 weeks ago |
| Description |
|
Hi there ! |
| Comments |
| Comment by Ravind Kumar (Inactive) [ 18/May/16 ] | |||||||||||||||||||||||||||||||||||||||
|
User wanted to create ObjectId in code without going to shell and parsing output of ObjectId(). Suggested the ObjectId() constructor using the driver associated to their code as a solution. | |||||||||||||||||||||||||||||||||||||||
| Comment by Ravind Kumar (Inactive) [ 25/Apr/16 ] | |||||||||||||||||||||||||||||||||||||||
|
Hello Nir, Your best option is to use the find() method , iterate through the cursor, and update each document using updateOne() and the $set operator. For example,
If what you want to do is to mutate or otherwise modify the ObjectID within a query, I suggest using the aggregation framework:
You can then use additional aggregation stages, expressions, or accumulators to modify and mutate the ObjectID as required. See Aggregation Pipeline Operators Let me know if this makes sense. |