7
以下服務器方法因爲找不到用戶而導致重複密鑰錯誤。一個典型的查詢是:{服務:{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
這是我的理解是服務器的方法有機會獲得在集合中的所有文件,爲什麼不能在用戶找到但插入由於重複的Facebook ID失敗?
這在我的osx dev環境中完美工作,但在我的ubuntu服務器(捆綁)上失敗並且在NODE_ENV = production下運行。
這裏是日誌輸出:
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)
我剛剛得到它的格式化查詢是這樣的:{「services.facebook.id」:「xxxx」}似乎嵌套太深了。我使用node-inspector在服務器上嘗試了各種查詢,發現嵌套3深度的查詢總是返回undefined。仍然不清楚爲什麼深層嵌套在OSX上工作並在Linux上失敗。 –