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

upsert: MongoError: The dotted field is not valid for storage #4522

Closed
gsuess opened this Issue Jun 7, 2015 · 2 comments

Comments

Projects
None yet
2 participants
@gsuess
Contributor

gsuess commented Jun 7, 2015

Steps to reproduce:

test = new Mongo.Collection("test");
test.update({"subdocument.field": "value1"}, {$set: {"foo": "baz"}}, {upsert: true});

Expected result:

Inserts a document:

{"_id":  "EQawgZfPaYszG9FYA",  "subdocument": {"field": "value1"}, "foo": "baz"}

Actual Result:

MongoError: The dotted field 'subdocument.field' in 'subdocument.field' is not valid for storage.
    at Object.Future.wait (/home/gsuess/WebstormProjects/meteor/dev_bundle/server-lib/node_modules/fibers/future.js:398:15)
    at [object Object].<anonymous> (/packages/meteor/helpers.js:119:1)
    at [object Object].MongoConnection.(anonymous function) [as update] (/packages/mongo/mongo_driver.js:698:1)
    at [object Object].Mongo.Collection.(anonymous function) [as update] (/packages/mongo/collection.js:575:1)
    at repl:1:7
    at /home/gsuess/WebstormProjects/meteor/examples/leaderboard/.meteor/local/build/programs/server/shell-server.js:264:23
    - - - - -
    at Object.toError (/home/gsuess/WebstormProjects/meteor/examples/leaderboard/.meteor/local/isopacks/npm-mongo/npm/node_modules/mongodb/lib/mongodb/utils.js:114:11)
    at /home/gsuess/WebstormProjects/meteor/examples/leaderboard/.meteor/local/isopacks/npm-mongo/npm/node_modules/mongodb/lib/mongodb/collection/core.js:577:27
    at /home/gsuess/WebstormProjects/meteor/examples/leaderboard/.meteor/local/isopacks/npm-mongo/npm/node_modules/mongodb/lib/mongodb/db.js:1195:7
    at /home/gsuess/WebstormProjects/meteor/examples/leaderboard/.meteor/local/isopacks/npm-mongo/npm/node_modules/mongodb/lib/mongodb/db.js:1903:9
    at Server.Base._callHandler (/home/gsuess/WebstormProjects/meteor/examples/leaderboard/.meteor/local/isopacks/npm-mongo/npm/node_modules/mongodb/lib/mongodb/connection/base.js:453:41)
    at /home/gsuess/WebstormProjects/meteor/examples/leaderboard/.meteor/local/isopacks/npm-mongo/npm/node_modules/mongodb/lib/mongodb/connection/server.js:487:18
    at [object Object].MongoReply.parseBody (/home/gsuess/WebstormProjects/meteor/examples/leaderboard/.meteor/local/isopacks/npm-mongo/npm/node_modules/mongodb/lib/mongodb/responses/mongo_reply.js:68:5)
    at [object Object].<anonymous> (/home/gsuess/WebstormProjects/meteor/examples/leaderboard/.meteor/local/isopacks/npm-mongo/npm/node_modules/mongodb/lib/mongodb/connection/server.js:445:20)
    at [object Object].emit (events.js:95:17)
    at [object Object].<anonymous> (/home/gsuess/WebstormProjects/meteor/examples/leaderboard/.meteor/local/isopacks/npm-mongo/npm/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:207:13)
    at [object Object].emit (events.js:98:17)
    at Socket.<anonymous> (/home/gsuess/WebstormProjects/meteor/examples/leaderboard/.meteor/local/isopacks/npm-mongo/npm/node_modules/mongodb/lib/mongodb/connection/connection.js:440:22)
    at Socket.emit (events.js:95:17)
    at Socket.<anonymous> (_stream_readable.js:765:14)
    at Socket.emit (events.js:92:17)
    at emitReadable_ (_stream_readable.js:427:10)
    at emitReadable (_stream_readable.js:423:5)
    at readableAddChunk (_stream_readable.js:166:9)
    at Socket.Readable.push (_stream_readable.js:128:10)
    at TCP.onread (net.js:529:21)

Notes:

When running the same query on mongo directly, it works just fine:

db.test.update({"subdocument.field": "value1"}, {$set: {"foo": "baz"}}, {upsert: true})
WriteResult({
        "nMatched" : 0,
        "nUpserted" : 1,
        "nModified" : 0,
        "_id" : ObjectId("5574737b843753e392cfa920")
})
@gsuess

This comment has been minimized.

Contributor

gsuess commented Jun 7, 2015

Meteor tries to do the following update query here:

db.test.update({ 'subdocument.field': 'value1' } ,{ _id: 'F6sdtKdxSrp8xRcFu','subdocument.field': 'value1', foo: 'bar' },{ safe: true, upsert: true })

This produces in mongo:

2015-06-07T19:29:34.726+0200 can't have . in field names [subdocument.field] at src/mongo/shell/collection.js:155

gsuess added a commit to gsuess/meteor that referenced this issue Jun 7, 2015

Fixes meteor#4522: Mongo upsert with dotted keys
Break down dotted key-value pairs into an object when simulating an insert.
@ekatek

This comment has been minimized.

Contributor

ekatek commented Jun 10, 2015

Makes sense to me -- it would be cool if this command worked in Meteor. Thanks for the catch and the pull request.

@dgreensp dgreensp closed this in e02bf0f Aug 19, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment