1

I'm trying to create an index and I'm getting this error:

2018-12-30T15:28:30.853-0800 I COMMAND [conn580067] command db.$cmd command: createIndexes { createIndexes: "node", indexes: [ { background: true, sparse: true, key: { type: 1, players: 1, ct: 1, image: 1, domain: 1 }, name: "browse" } ], writeConcern: {} } exception: WiredTigerIndex::insert: key too large to index, failing 5813 { : "card", : null, : 1390347921368.0, : "/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxISEBIUEhQVFhQQEBAQDxAVFA8UFBUQFBQWFxQRFBQYHCggGBolHBQUITEhJSkrLi4uFx8zODMsNygtLisBCgoKDg0NFBAQFywcHBwsLCwsLCwsLC...", : null } code:17280 numYields:3312 reslen:354 locks:{ Global: { acquireCount: { r: 3313, w: 3313 } }, Database: { acquireCount: { w: 3313, W: 2 } }, Collection: { acquireCount: { w: 3313 } }, Metadata: { acquireCount: { W: 1 } } } protocol:op_query 8206ms

How do I figure out which document it is so that I can delete it?

mongod version: 3.4.11 (WiredTiger)

  • What is the MongoDB version(x,y,z)? – Md Haidar Ali Khan Dec 31 '18 at 3:54
  • @MdHaidarAliKhan mongod version: 3.4.11 (WiredTiger) – Harry Dec 31 '18 at 4:22
  • 3
    The total BSON size and fields in the offending key are included in the error message. It looks like this key would have been 5813 bytes and most of the fields are null. The image field includes a binary JPEG image which is probably both unhelpful to index and the main cause of excessive key length. Creating the index definition without image would probably work unless other fields include very long values. – Stennie Dec 31 '18 at 6:40
  • A sparse compound index is also probably not going to do what you expect: an index entry will be created as long as the document contains at least one of the keys, but this index may not be useful depending on your queries. Sparse indexes will not be selected where doing so could result in an incomplete result set for queries and sort operations. It would be worth reviewing explain results in a development/staging environment. – Stennie Dec 31 '18 at 6:40
  • 1
    If you have an expected pattern for your image fields you can use a regular expression to find values that don't start with the expected string value(s). For example, if the image urls should start with http(s), you could use: db.myCollection.find({image: { $not: /^http/ }}, { _id: 1 }) to print the _ids for suspect values. – Stennie Dec 31 '18 at 7:55

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.