Search meteor user on server

The following server method throws repetitive key errors as users are not found. Typical request: {services: {facebook: {id: 'XXXX'}}}

Meteor.methods getUser: (query, data = {}) -> user = Meteor.users.findOne(query) return user if user? user = _.extend(data, query) user._id = Meteor.users.insert user return user 

As far as I understand, server methods have access to all documents in collections, why not find the user, but the insert failed because of duplicate facebook identifier?

This works fine in my osx dev environment, but it crashes on my ubuntu server (included) and works with NODE_ENV = production.

Here is the log output:

 data: { services: { facebook: { id: 'xxxx' } } } (the query provided to getUser) data: undefined (the result of findOne) data: Exception while invoking method 'getUser' MongoError: E11000 duplicate key error index: thunderstruck.users.$services.facebook.id_1 dup key: { : "xxxx" } data: at Db.wrap (/home/jeremy/deploy/thunderstruck/releases/20121105202012/bundle/server/node_modules/mongodb/lib/mongodb/db.js:1904:11) data: at null.<anonymous> (/home/jeremy/deploy/thunderstruck/releases/20121105202012/bundle/server/node_modules/mongodb/lib/mongodb/collection.js:320:26) data: at g (events.js:192:14) data: at EventEmitter.emit (events.js:126:20) data: at Db._callHandler (/home/jeremy/deploy/thunderstruck/releases/20121105202012/bundle/server/node_modules/mongodb/lib/mongodb/db.js:1439:25) data: at Server.connect.connectionPool.on.server._serverState (/home/jeremy/deploy/thunderstruck/releases/20121105202012/bundle/server/node_modules/mongodb/lib/mongodb/connection/server.js:425:30) data: at MongoReply.parseBody (/home/jeremy/deploy/thunderstruck/releases/20121105202012/bundle/server/node_modules/mongodb/lib/mongodb/responses/mongo_reply.js:127:5) data: at Server.connect.connectionPool.on.server._serverState (/home/jeremy/deploy/thunderstruck/releases/20121105202012/bundle/server/node_modules/mongodb/lib/mongodb/connection/server.js:384:22) data: at EventEmitter.emit (events.js:96:17) data: at _connect (/home/jeremy/deploy/thunderstruck/releases/20121105202012/bundle/server/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:136:13) 
+7
source share
1 answer

These are different MongoDB queries, and you definitely want to use the dot style that you switched to. See the Mongo Dot Notation Documentation.

 Meteor.users.find({"services.facebook.id": "foo"}) 

will return any document that has a built-in property that you are looking for with the value foo .

 Meteor.users.find({services: {facebook: {id: "foo"}}}) 

Only matches documents with this structure. If the embedded facebook document has other fields, it will not match. Most likely, the document in your production database has more fields, and therefore you do not get a match.

+14
source

All Articles