Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor: return an error if bulk_write is called on an unsupported server #1117

Merged

Conversation

isabelatkinson
Copy link
Contributor

@isabelatkinson isabelatkinson commented Jun 4, 2024

Attempting to call bulk_write on a 7.0 server currently yields the following error:

Error: Error { kind: Command(CommandError { code: 40415, code_name: "Location40415", message: "BSON field 'bulkWrite.errorsOnly' is an unknown field.", topology_version: None }), labels: {}, wire_version: Some(21), source: None }

This PR adds a more informative error to avoid confusion if/when users attempt to use this feature with 7.0.

This is a temporary fix; once the server error is improved, we can remove this check (SERVER-91171).

@isabelatkinson isabelatkinson marked this pull request as ready for review June 4, 2024 18:19
@isabelatkinson isabelatkinson merged commit 2057ddc into mongodb:main Jun 4, 2024
3 of 6 checks passed
@isabelatkinson isabelatkinson deleted the bulk-write-server-error branch June 28, 2024 16:06
@msf
Copy link

msf commented Sep 13, 2024

I just hit this issue and I'm puzzled, because I'm certain that bulk_write or db.collection.bulkWrite() works on v7 (and according to the docs even older versions).

For example, here is this command working in v7.0:

test> db.test.bulkWrite([ {replaceOne:{ "filter": {"_id": "1"}, "replacement": { "foo":"bar"}, "upsert":true}}])
{
  acknowledged: true,
  insertedCount: 0,
  insertedIds: {},
  matchedCount: 0,
  modifiedCount: 0,
  deletedCount: 0,
  upsertedCount: 1,
  upsertedIds: { '0': '1' }
}
test> db.test.bulkWrite([ {replaceOne:{ "filter": {"_id": "1"}, "replacement": { "foo":"ballla"}, "upsert":true}}])
{
  acknowledged: true,
  insertedCount: 0,
  insertedIds: {},
  matchedCount: 1,
  modifiedCount: 1,
  deletedCount: 0,
  upsertedCount: 0,
  upsertedIds: {}
}
test> db.test.bulkWrite([ {replaceOne:{ "filter": {"_id": "2"}, "replacement": { "foo":"balla"}, "upsert":true}}])
{
  acknowledged: true,
  insertedCount: 0,
  insertedIds: {},
  matchedCount: 0,
  modifiedCount: 0,
  deletedCount: 0,
  upsertedCount: 1,
  upsertedIds: { '0': '2' }
}
test> quit;
root@d545ed1cbbd0:/# mongosh
Current Mongosh Log ID:	66e461290c4124dc2cc76a8a
Connecting to:		mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.3.0
Using MongoDB:		7.0.14

@isabelatkinson
Copy link
Contributor Author

Hi @msf, db.collection.bulkWrite() is a different API from client.bulkWrite(). The client-level method uses the new bulkWrite server command, which is only supported on MongoDB 8.0+. The driver only supports the client-level API.

@msf
Copy link

msf commented Sep 18, 2024

Is there a collection.bulkWrite api on the rust mongodb driver? I didnt find it

Thanks for your reply!

@isabelatkinson
Copy link
Contributor Author

The Rust driver does not support the collection-level bulk write method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants