parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

Using Mongolab, saving regular parse objects produces : MongoError: exception: Btree::insert: key too large to index, failing

Open degenddy opened this issue 10 years ago • 7 comments

Parse hosted server runs fine. I'm in the process of migrating my server and now I receive this error when saving an object: (XXXXX are keys I've obfuscated for this post...)

 MongoError: exception: Btree::insert: key too large to index, failing test_parse_server.RefFollowerUser.$_p_follower_1__p_user_1 1622 { : "_User$ilnDsp7JHh", : { lastActive: new Date(1456266521816), searchable: { __type: "Pointer", className: "Searchable", objectId: "szd8JUJG89" }, googleLogin: false, facebookLogin: true, nickname: "XXXXX", searchPhrase: "XXXXX", username: "3379hGpzOxdwSClGdXun8O8Z2", updatedAt: new Date(1456266527688), email: "[email protected]", authData: { facebook: { access_token: "XXXXX", expiration_date: "2016-04-21T14:04:11.000Z", id: "XXXXX" } }, privateProfile: false, createdAt: new Date(1421380522173), profilePicture: { __type: "File", name: "tfss-c34ad0d3-51fd-49c6-94d5-799c5ffd9a7d-file", url: "XXXXX" }, followersCount: 175, emailVerified: false, twitterLogin: false, shoutsCount: 73, gender: "male", coverUrl: "XXXXX", state: 1, enc: { __type: "Pointer", className: "UserEnc", objectId: "MJO7pdkj96" }, photoUrl: "XXXXX", countryCode: "il", hideSuggestions: true, socialId: "XXXXX", shouldSentJoinNotification: false, rank: 100, objectId: "yEVzdLRHgu", __type: "Object", className: "_User" } }
    at Function.MongoError.create (c:\PROJECTS\shout-server\shout-server\node_modules\mongodb\node_modules\mongodb-core\lib\error.js:31:11)
    at commandCallback (c:\PROJECTS\shout-server\shout-server\node_modules\mongodb\node_modules\mongodb-core\lib\topologies\server.js:929:66)
    at Callbacks.emit (c:\PROJECTS\shout-server\shout-server\node_modules\mongodb\node_modules\mongodb-core\lib\topologies\server.js:116:3)
    at messageHandler (c:\PROJECTS\shout-server\shout-server\node_modules\mongodb\node_modules\mongodb-core\lib\topologies\server.js:282:23)
    at Socket.dataHandler (c:\PROJECTS\shout-server\shout-server\node_modules\mongodb\node_modules\mongodb-core\lib\connection\connection.js:273:22)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at readableAddChunk (_stream_readable.js:146:16)
    at Socket.Readable.push (_stream_readable.js:110:10)
    at TCP.onread (net.js:523:20)

degenddy avatar Feb 23 '16 22:02 degenddy

This is due to large indexed documents. On Parse.com we use the failIndexKeyTooLong=false option in Mongo however that will cause documents to not get indexed, so if you can, we recommend you change your db structure to reduce the size of your documents.

drew-gross avatar Feb 23 '16 22:02 drew-gross

Yes, I've read about this just now. So I can't set this on mongoLab I guess.. How can I reduce? My DB isn't big at all. What am I supposed to reduce? count of objects per table? column count? Please be as specific as possible. this migration is a pain in the ***.

degenddy avatar Feb 23 '16 22:02 degenddy

Its not the size of the db, it's the size of the parse object. Your parse object looks like it has a lot of columns, so I'd suggest splitting it into two objects in separate classes that are connected via a pointer. You may also be able to just delete the indexes you aren't using.

MongoLab does allow you to change this parameter on some database types, I believe, although that may not include any of the free ones.

drew-gross avatar Feb 23 '16 23:02 drew-gross

Oh. I'll try splitting this table. Is the data itself an issue? Meaning if I had only one column but one value was big amount of text, was this also a problem?

degenddy avatar Feb 23 '16 23:02 degenddy

Yes, that is also a problem. It would be same problem if you have one column that contained a very large array.

drew-gross avatar Feb 23 '16 23:02 drew-gross

Ok I think I figured out the problem. for some reasons, in cloud code: if I get an object by it's ObjectId and then set it to the reference field of other object it duplicates the object put it in the reference field instead of just setting it's reference (the android API works ok).

here's my code (user is from request.object, shoutUser is the one i'm getting with query and "get"):

var userQuery = new Parse.Query('_User');
                userQuery.get("4GJ9QWcecT", {useMasterKey: true})
                    .then(function (shoutUser) {

                        var RefFollowerUser = Parse.Object.extend("RefFollowerUser");
                        var refFollowerUser = new RefFollowerUser();

                        setACLIfNull(refFollowerUser);

                        refFollowerUser.set("user", shoutUser);

                        refFollowerUser.set("follower", user);

                        return refFollowerUser.save(null, {useMasterKey: true});

                    });

in Parse hosted server it works good, I mean I don't really know how the mongo objects look like, but the ui shows a reference to the user and not the entire json.

degenddy avatar Feb 24 '16 07:02 degenddy

That sounds like a different problem. Could you open a separate issue for that?

drew-gross avatar Feb 24 '16 18:02 drew-gross