日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > php教程 > Meteor update等操作失敗原因及解決方法

Meteor update等操作失敗原因及解決方法

來源:程序員人生   發布時間:2015-05-19 08:23:51 閱讀次數:5465次

Meteor 提供了兩個 MongoDB 數據庫:1個客戶端緩存數據庫服務器上的1個 MongoDB 數據庫。當1個用戶更改1些數據時(例如通過單擊 Save),在閱讀器中運行的 JavaScript 代碼會更新本地 MongoDB 中的相應的數據庫項,然后向服務器發出1個 DDP 要求。該代碼立即像操作已取得成功那樣繼續運行,由于它不需要等待服務器回復。與此同時,服務器在后臺更新。如果服務器操作失敗或返回1個意外結果,那末客戶端 JavaScript 代碼會根據從服務器新返回的數據立即進行調劑。

昨天寫代碼的時候發現,發現有1個update操作總是失敗,而也沒有甚么毛病提示,只顯示個error。找了很久找不到問題出在哪。
這里寫圖片描述

然后去讀官方文檔,它是這樣寫的:


文檔中關于update的說明:
collection.update(selector, modifier, [options], [callback]) Anywhere

Modify one or more documents in the collection

Arguments

selector Mongo selector, or object id

Specifies which documents to modify

modifier Mongo modifier

Specifies how to modify the documents

callback Function

Optional. If present, called with an error object as its argument.

Options

multi Boolean

True to modify all matching documents; false to only modify one of the matching documents (the default).

再查看1次我寫的代碼,應當沒錯的。然后再mongodb的命令行工具上試試履行一樣語句也是可以的,因而我就覺得是Meteor的相干設置問題。

再往文檔中細看,發現問題了:


The behavior of update differs depending on whether it is called by trusted or untrusted code. Trusted code includes server code and method code. Untrusted code includes client-side code such as event handlers and a browser’s JavaScript console.

  • Trusted code can modify multiple documents at once by setting multi to true, and can use an arbitrary Mongo selector to find the documents to modify. It bypasses any access control rules set up by allow and deny.

  • Untrusted code can only modify a single document at once, specified by its _id. The modification is allowed only after checking any applicable allow and deny rules.


原來為了安全性,Meteor限制了在客戶端下默許的對數據庫的操作,對insert,update,remove等操作的selector只能為 _id,并且不能使用mutil等,所以我寫的那條update語句的毛病在于selector用了_id外的條件。所以看來解決方法有兩個:

  • 在客戶端只是用_id作為selector的操作,明顯這樣不方便
  • 服務器端寫allow規則, 允許客戶端直接對數據庫進行這些操作

文檔中關于allow的說明:
collection.allow(options) Server

Allow users to write directly to this collection from client code, subject to limitations you define.
Options

insert, update, remove Function

Functions that look at a proposed modification to the database and return true if it should be allowed.

因而寫了相干的allow規則, 讓他在某個情況下return true就能夠了

生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 偷拍亚洲色图 | 日韩在线播放视频 | 久久久久网站 | 国产高清在线观看 | 天堂tv| 欧美a在线| 91看片免费在线观看 | 曰韩一级片 | 亚洲va欧美va人人爽成人影院 | 日韩一区二区成人 | 久久噜| 国产成人在线观看免费网站 | 成av在线| 一区二区三区在线视频播放 | 99久久99久久精品免费看蜜桃 | 麻豆黄网 | 日本久久中文字幕 | 久久五月天婷婷 | 天天拍夜夜拍 | 日韩av一区在线 | 91精品国产综合久久精品图片 | 成人第一区 | 亚洲精品国产精品乱码在线观看 | 精品国产黄 | 免费a v视频 | 999久久久免费精品国产 | 日日操天天操夜夜操 | 精品国产一区二区三区日日嗨 | 久久国产成人精品av | 黑人网站 | 俄罗斯精品一区二区三区 | 国产精品国产a级 | 精品国产不卡一区二区三区 | 午夜欧美一区二区三区在线播放 | 岛国视频在线 | 天堂av2020 | 亚洲综合99 | 日本韩国欧美 | 国产激情一区二区三区在线观看 | 亚洲成人精选 | 综合久久久久久久久久 |