2016-12-16 67 views
0

我剛纔注意到,每當使用預定義變量MongoDB中保存任何數據類型從Number和Boolean改爲字符串流星蒙戈保存/插入數字轉換成字符串

Orders = new Mongo.Collection("Orders"); 
Orders.update({_id:"12345"},{$set:{price:5.5}) //this works 

var price = {price: 5.5}; 
Orders.update({_id:"12345"},{$set:price}); //this is not working anymore in the mongo collection price is saved as String "5.5" not as a number, same goes for Boolean values 

誰能幫助我在哪最近怎麼樣?更改整個應用程序以使用第一種方法並不是一種解決方案,因爲我的代碼生成了數千次更新,這些更新以前完美運行。

+0

你能展示你是如何定義你的訂單模式流星? –

+0

這是否也發生在一個新的應用程序?如果不是,你使用了什麼軟件包? – MasterAM

回答

0

可以聲明變量時,你試試這個:

var price = {price: Number(5.5)}; 
Orders.update({_id:"12345"},{$set:price}); 

通過這種方式,我認爲它可以確保5.5確實是一個數字,當它試圖更新相關數據。對於布爾值,你可以使用Boolean(true)以及我猜