[DOCS-9634] Comment on: "manual/tutorial/create-an-auto-incrementing-field.txt" Created: 09/Dec/16  Updated: 03/Nov/17  Resolved: 09/Dec/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: Cannot Reproduce Votes: 0
Labels: collector-298ba4e7
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Node v4.4.7 on Debian

Location: https://docs.mongodb.com/v3.0/tutorial/create-an-auto-incrementing-field/
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.98 Safari/537.36
Referrer: https://www.google.com/
Screen Resolution: 1440 x 900


Participants:
Days since reply: 7 years, 9 weeks, 5 days ago

 Description   

findAndModify() not defined. Needs to be findOneAndUpdate().



 Comments   
Comment by Ravind Kumar (Inactive) [ 09/Dec/16 ]

Thank you for filing a DOCS ticket.

I tested on MongoDB version 3.0.9 and can confirm that findAndModify is defined:

 
> db.foo.find()
{ "_id" : ObjectId("584b02d5f3cd9908f61fd454"), "foo" : 1 }
{ "_id" : ObjectId("584b02d5f3cd9908f61fd455"), "foo" : 2 }
{ "_id" : ObjectId("584b02d5f3cd9908f61fd456"), "foo" : 3 }
{ "_id" : ObjectId("584b02d5f3cd9908f61fd457"), "foo" : 4 }
{ "_id" : ObjectId("584b02d5f3cd9908f61fd458"), "foo" : 5 }
{ "_id" : ObjectId("584b02d5f3cd9908f61fd459"), "foo" : 6 }
{ "_id" : ObjectId("584b02d5f3cd9908f61fd45a"), "foo" : 7 }
{ "_id" : ObjectId("584b02d5f3cd9908f61fd45b"), "foo" : 8 }
{ "_id" : ObjectId("584b02d5f3cd9908f61fd45c"), "foo" : 9 }
> db.foo.findAndModify( { query: {"foo" : 5}, update: {$set: {"bar" : 5 }} } )
{ "_id" : ObjectId("584b02d5f3cd9908f61fd458"), "foo" : 5 }
> db.foo.findAndModify( { query: {"foo" :{ $gt : 5}}, update: {$set: {"bar" : 5 }} } )
{ "_id" : ObjectId("584b02d5f3cd9908f61fd459"), "foo" : 6 }
> db.foo.find()
{ "_id" : ObjectId("584b02d5f3cd9908f61fd454"), "foo" : 1 }
{ "_id" : ObjectId("584b02d5f3cd9908f61fd455"), "foo" : 2 }
{ "_id" : ObjectId("584b02d5f3cd9908f61fd456"), "foo" : 3 }
{ "_id" : ObjectId("584b02d5f3cd9908f61fd457"), "foo" : 4 }
{ "_id" : ObjectId("584b02d5f3cd9908f61fd458"), "foo" : 5, "bar" : 5 }
{ "_id" : ObjectId("584b02d5f3cd9908f61fd459"), "foo" : 6, "bar" : 5 }
{ "_id" : ObjectId("584b02d5f3cd9908f61fd45a"), "foo" : 7 }
{ "_id" : ObjectId("584b02d5f3cd9908f61fd45b"), "foo" : 8 }
{ "_id" : ObjectId("584b02d5f3cd9908f61fd45c"), "foo" : 9 }

If you are having errors or issues running findAndModify, please create a ticket specifying the exact code run on the mongod instance and the exact error or output.

Generated at Thu Feb 08 07:58:48 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.