[JAVA-1270] Class WriteResult Method getN() always return 0 Created: 10/Jun/14 Updated: 23/Jun/15 Resolved: 23/Jun/15 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | Documentation |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | ||
| Reporter: | Docs Collector User (Inactive) | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | collector-298ba4e7 | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
my environment : Location: http://www.mongodb.org/about/support/ |
||
| Description |
|
DBObject user = new BasicDBObject(); method wr.getN() return 0 both with insert and save, Reporter: luoch |
| Comments |
| Comment by Jeffrey Yemin [ 23/Jun/15 ] |
|
In the new CRUD API introduced in 3.0, the insertOne/insertMany methods on MongoCollection return void. The number of documents inserted is either one for insertOne, or n for insertMany, where n equals the number of documents passed to insertMany. There is no need for these methods to return n, since it's value is implied by the method name and/or their arguments. |
| Comment by Jeffrey Yemin [ 16/Dec/14 ] |
|
Only by using the bulk write support introduced in 2.12.0. See http://api.mongodb.org/java/current/com/mongodb/BulkWriteOperation.html for details. |
| Comment by Tyler Hale [ 16/Dec/14 ] |
|
Is there any other way to retrieve the number of documents that were successfully inserted? |
| Comment by sjkyspa [ 09/Jul/14 ] |
|
getUpsertedId() |
| Comment by Jeffrey Yemin [ 10/Jun/14 ] |
|
It's by design. The getlasterror command has always return n : 0 for inserts, and the driver is just mirroring that response. 'n' in this case represents the number of documents matched by the query (for update and remove), and there is no query for insert, so it's always 0. |